我在一个简单的发布请求中收到错误“TypeError:无法读取未定义的属性'_id'”,以将文档保存到名为的集合books
中,我的有效负载如下所示:
{
"name": "practical view",
"author": "DN",
"location": "room 50"
}
我只是db.books.save()
在我的快递路线上做。由于我没有传递 id,因此理想情况下应该可以,但在这种情况下不行。
以下是我在节点服务器上得到的完整错误转储:
C:\NodeProjects\ExpressTutorial\Library\node_modules\mongojs\node_modules\mongodb\lib\mongodb\mongo_client.js:411
throw err
^
TypeError: Cannot read property '_id' of undefined
at Collection.save (C:\NodeProjects\ExpressTutorial\Library\node_modules\mongojs\node_modules\mongodb\lib\mongodb\collection.js:393:15)
at C:\NodeProjects\ExpressTutorial\Library\node_modules\mongojs\index.js:203:65
at apply (C:\NodeProjects\ExpressTutorial\Library\node_modules\mongojs\node_modules\thunky\index.js:16:28)
at C:\NodeProjects\ExpressTutorial\Library\node_modules\mongojs\node_modules\thunky\index.js:20:25
at Db.collection (C:\NodeProjects\ExpressTutorial\Library\node_modules\mongojs\node_modules\mongodb\lib\mongodb\db.js:488:44)
at C:\NodeProjects\ExpressTutorial\Library\node_modules\mongojs\index.js:268:7
at apply (C:\NodeProjects\ExpressTutorial\Library\node_modules\mongojs\node_modules\thunky\index.js:16:28)
at C:\NodeProjects\ExpressTutorial\Library\node_modules\mongojs\node_modules\thunky\index.js:20:25
at C:\NodeProjects\ExpressTutorial\Library\node_modules\mongojs\index.js:300:4
at C:\NodeProjects\ExpressTutorial\Library\node_modules\mongojs\node_modules\mongodb\lib\mongodb\mongo_client.js:408:11
31 Aug 00:14:30 - [nodemon] app crashed - waiting for file changes before starting...