更新到Mongoose(6.6.1
)的最新版本后,文档的.保存()现在出现错误,而之前的保存没有问题。这是关于一个字段的验证,标记为Date
,但对我来说似乎没问题。无论如何,我得到了错误owner.$populated is not a function
。
问题是什么?为什么错误涉及owner
字段?
这是对象
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();
这是结构描述
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 }
});
这是错误:
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)
1条答案
按热度按时间13z8s7eq1#
在一些检查之后,我发现package.json中列出的一个包与mongoose的一个旧版本有依赖关系。
更新该软件包以使用最新版本的Mongoose,似乎工作!