Node.js (节点:11168)未处理的PromisejectionWarning:ValidationError:列表验证失败

Node.js (节点:11168)未处理的PromisejectionWarning:ValidationError:列表验证失败,node.js,mongodb,mongoose,Node.js,Mongodb,Mongoose,我正在处理待办事项列表这是一个宠物项目,我遇到了一个错误: (节点:11168)未处理的PromisejectionWarning:ValidationError:列表验证失败:项。3.\u id:对路径“\u id”处的值“sas”转换为ObjectId失败。 完全错误: (node:11168) UnhandledPromiseRejectionWarning: ValidationError: List validation failed: items.3._id: Cast to Obj

我正在处理待办事项列表这是一个宠物项目,我遇到了一个错误:
(节点:11168)未处理的PromisejectionWarning:ValidationError:列表验证失败:项。3.\u id:对路径“\u id”处的值“sas”转换为ObjectId失败。

完全错误:

(node:11168) UnhandledPromiseRejectionWarning: ValidationError: List validation failed: items.3._id: Cast to ObjectId failed for value "sas" at path "_id"
    at model.Document.invalidate (C:\Users\Lenovo\Documents\todolist-v2-starting-files\node_modules\mongoose\lib\document.js:2688:32)
    at EmbeddedDocument.invalidate (C:\Users\Lenovo\Documents\todolist-v2-starting-files\node_modules\mongoose\lib\types\embedded.js:292:29)
    at EmbeddedDocument.$set (C:\Users\Lenovo\Documents\todolist-v2-starting-files\node_modules\mongoose\lib\document.js:1301:12)
    at EmbeddedDocument.$set (C:\Users\Lenovo\Documents\todolist-v2-starting-files\node_modules\mongoose\lib\document.js:1010:16)
    at EmbeddedDocument.Document (C:\Users\Lenovo\Documents\todolist-v2-starting-files\node_modules\mongoose\lib\document.js:150:12)
    at EmbeddedDocument [as constructor] (C:\Users\Lenovo\Documents\todolist-v2-starting-files\node_modules\mongoose\lib\types\embedded.js:42:12)
    at new EmbeddedDocument (C:\Users\Lenovo\Documents\todolist-v2-starting-files\node_modules\mongoose\lib\schema\documentarray.js:115:17)
    at CoreDocumentArray._cast (C:\Users\Lenovo\Documents\todolist-v2-starting-files\node_modules\mongoose\lib\types\documentarray.js:109:12)
    at CoreDocumentArray._mapCast (C:\Users\Lenovo\Documents\todolist-v2-starting-files\node_modules\mongoose\lib\types\core_array.js:272:17)
    at Arguments.map (<anonymous>)
    at CoreDocumentArray.push (C:\Users\Lenovo\Documents\todolist-v2-starting-files\node_modules\mongoose\lib\types\core_array.js:670:21)
    at CoreDocumentArray.push (C:\Users\Lenovo\Documents\todolist-v2-starting-files\node_modules\mongoose\lib\types\documentarray.js:210:28)
    at C:\Users\Lenovo\Documents\todolist-v2-starting-files\app.js:76:35
    at C:\Users\Lenovo\Documents\todolist-v2-starting-files\node_modules\mongoose\lib\model.js:4846:16
    at C:\Users\Lenovo\Documents\todolist-v2-starting-files\node_modules\mongoose\lib\model.js:4846:16
    at C:\Users\Lenovo\Documents\todolist-v2-starting-files\node_modules\mongoose\lib\helpers\promiseOrCallback.js:24:16
(node:11168) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:11168) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
据我所知。推送>>
foundCustomList.items.push(itemName)时出现此错误

这是模式定义

const listSchema = {
  name: String,
  items: [itemsSchema]
};

const List = mongoose.model("List", listSchema);
它正在使用itemsSchema

const itemsSchema = {
  name: String
};

const Item = mongoose.model("Item", itemsSchema);

请包含架构定义。您可以使用mongodb语法推送数据,
List.findOneAndUpdate({name:listTitle},{$push:{yourtItemArrayNamehere:itemName}})。然后(data=>{})。catch(err=>{})
,如果您使用mongoose,在进行查询之前,您需要首先使用mongoose架构。请包含架构定义。您可以使用mongodb语法,
List.findOneAndUpdate({name:listTitle},{$push:{yourItemArrayNameHere:itemName}})。然后(data=>{})。catch(err=>{})
,如果您使用mongoose,在进行查询之前需要先使用mongoose架构
const itemsSchema = {
  name: String
};

const Item = mongoose.model("Item", itemsSchema);