猫鼬无法在模式中保存子文档数组
Mongoose cant save with subdocument array in schema
我用一个嵌套的子文档数组制作了这个 mongoose 模式:
const deliverySchema = new db.Schema({
price: Number
})
const suppliersSchema = new db.Schema({
name: String,
deliveries: [deliverySchema]
})
exports.Suppliers = db.model('Suppliers', suppliersSchema)
const suppliers = new Suppliers({name})
await suppliers.save()
但是当我尝试保存文档时出现此错误:
TypeError: Cannot read properties of undefined (reading 'length')
at cloneArray...
如果我从模式中删除子文档,文档将被毫无问题地保存。
为什么我无法使用此架构保存文档?
我不能确切地说出问题出在哪里,但我决定重新安装所有 npm 包,问题就解决了。
因此,对于遇到此问题并希望避免用药的任何人,只需删除您的 npm 文件夹并重新安装即可。这可能是一个解决方案。
我用一个嵌套的子文档数组制作了这个 mongoose 模式:
const deliverySchema = new db.Schema({
price: Number
})
const suppliersSchema = new db.Schema({
name: String,
deliveries: [deliverySchema]
})
exports.Suppliers = db.model('Suppliers', suppliersSchema)
const suppliers = new Suppliers({name})
await suppliers.save()
但是当我尝试保存文档时出现此错误:
TypeError: Cannot read properties of undefined (reading 'length')
at cloneArray...
如果我从模式中删除子文档,文档将被毫无问题地保存。
为什么我无法使用此架构保存文档?
我不能确切地说出问题出在哪里,但我决定重新安装所有 npm 包,问题就解决了。
因此,对于遇到此问题并希望避免用药的任何人,只需删除您的 npm 文件夹并重新安装即可。这可能是一个解决方案。