Versions:
mongoose@4.11.5
mongodb Server version: 3.4.7
Model:
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
var CheckSchema = new Schema({
providerName: String,
number: String,
date: { type: Date },
dateReceived: { type: Date },
amount: Schema.Types.Decimal,
paymentType: String,
comment: String,
status: String,
images: [Image],
transactions: [Transaction],
rejectedTransactions: [Transaction],
payerName: String
});
server code:
Check.create(newCheck, function (err, check) {
if (err) {
return _response.handleError(req, res, err, _logType);
}
return _response.handleSuccess(req, res, 200, _logType, check);
});
Returns this error:
Check validation failed: amount: Cast to Decimal128 failed for value
"123.98" at path "amount"
ValidationError
"amount" is coming from the client as a number. When I stringify "amount" it succussfully stores to the db as a Decimal128 type.
newCheck.amount = newCheck.amount.toString();
I do not want to do that everytime I create a new check. I have a large app that I want to change multiply values to Decimal128. Is there something I am missing in my setup?