After updating to last version of Mongoose (6.6.1), the .save() of a Document now raises an error, while before was saving without problems.
It's about the validation of a field, marked as Date, but it seems ok to me. Anyway I get the error owner.$populated is not a function.
What's the problem? And why the error talks about ownerfield?
This is the Object
new MyTask({
"source": {
"client_id" : "ABC",
"ip" : "127.0.0.1"
},
"invoice": {
"amount" : 1000,
"currency" : "eur",
"dueAt" : "2022-10-23T14:55:57.482Z",
"issuedAt" : "2022-07-25T13:55:57.480Z",
"number" : "724/001"
}
}).save();
This is the Schema
var invoice_schema = new Schema({
"amount" : {type:Number, required:true},
"currency" : {type:String, required:true},
"dueAt" : {type:Date, required:true},
"issuedAt" : {type:Date, required:true},
"number" : {type:String}
},
{
timestamps:true,
toObject : { virtuals: true },
toJSON : { virtuals: true }
});
var MYTASK_SCHEMA = new Schema(
{
source : {
ip : {type: String},
client_id : {type: String}
},
invoice: {type : invoice_schema}
},
{
timestamps:true,
toObject: { virtuals: true },
toJSON : { virtuals: true }
});
And this is the error:
Error: MyTask validation failed:
invoice.dueAt: owner.$populated is not a function,
invoice.issuedAt: owner.$populated is not a function,
invoice: Validation failed:
dueAt: owner.$populated is not a function,
issuedAt: owner.$populated is not a function
at ValidationError.inspect (/app/node_modules/mongoose/lib/error/validation.js:48:26)
at formatValue (node:internal/util/inspect:790:19)
at inspect (node:internal/util/inspect:350:10)
at formatWithOptionsInternal (node:internal/util/inspect:2241:40)
at formatWithOptions (node:internal/util/inspect:2103:10)
at console.value (node:internal/console/constructor:348:14)
at console.warn (node:internal/console/constructor:381:61)