如果不指定模式,拉动将不起作用

问题描述 投票:0回答:0

未定义数组时拉入mongodb不执行

const itemsScema = {
  name: String
}

const listSchema = {
  name: String,//list name
  items: []
}

当 items 数组未定义为 itemsSchema 时,下面的代码行不起作用。

List.findOneAndUpdate({ name: listName }, { $pull: { items: { _id: checkeditemID} }}).then(result=>{
...
})

当 listSchema 修改为:

时它工作正常
const listSchema = {
  name: String,//list name
  items: [itemsScema]
}

为什么在 items 数组中提供 itemsSchema 使其能够运行并拉动执行?

node.js mongodb nosql mongoose-schema database-schema
© www.soinside.com 2019 - 2024. All rights reserved.