0
在我的后端我要删除的文件,由它在我的MongoDB DATABSE ID标记。因此我使用下面的代码。但是,而不是删除它,它抛出一个错误,它不能设置未定义猫鼬findByIdAndRemove()抛出错误
代码的财产“_id”:
Seller.findByIdAndRemove("594801105cb8571868f9cd55",function (err) {
console.log(err);
});
错误:
TypeError: Cannot set property '_id' of undefined
at resetId (Z:\Documents\Programming\Projext XY\repo\node_modules\mongoose\lib\schema\objectid.js:204:16)
at ObjectId.SchemaType._applySetters (Z:\Documents\Programming\Projext XY\repo\node_modules\mongoose\lib\schematype.js:637:22)
at ObjectId.SchemaType.applySetters (Z:\Documents\Programming\Projext XY\repo\node_modules\mongoose\lib\schematype.js:661:16)
at ObjectId.SchemaType._castForQuery (Z:\Documents\Programming\Projext XY\repo\node_modules\mongoose\lib\schematype.js:1021:17)
at ObjectId.castForQuery (Z:\Documents\Programming\Projext XY\repo\node_modules\mongoose\lib\schema\objectid.js:189:15)
at cast (Z:\Documents\Programming\Projext XY\repo\node_modules\mongoose\lib\cast.js:232:32)
at model.Query.Query.cast (Z:\Documents\Programming\Projext XY\repo\node_modules\mongoose\lib\query.js:2933:12)
at castQuery (Z:\Documents\Programming\Projext XY\repo\node_modules\mongoose\lib\query.js:2835:18)
at model.Query.Query._findAndModify (Z:\Documents\Programming\Projext XY\repo\node_modules\mongoose\lib\query.js:1980:17)
at model.Query.Query.findOneAndRemove (Z:\Documents\Programming\Projext XY\repo\node_modules\mquery\lib\mquery.js:2585:15)
at model.Query.Query._findOneAndRemove (Z:\Documents\Programming\Projext XY\repo\node_modules\mongoose\lib\query.js:1944:31)
at Z:\Documents\Programming\Projext XY\repo\node_modules\kareem\index.js:257:8
at Z:\Documents\Programming\Projext XY\repo\node_modules\kareem\index.js:23:7
at _combinedTickCallback (internal/process/next_tick.js:73:7)
at process._tickCallback (internal/process/next_tick.js:104:9)
问题寻求帮助调试(**“为什么不是这个代码的工作?” **)必须包括所期望的行为,一*特定问题或错误,并在最短的代码必要*在问题本身**中重现它**。没有**明确问题陈述**的问题对其他读者无用。 参见:[如何创建最小,完整的,并且可验证示例](http://stackoverflow.com/help/mcve) –
在这种情况下它意味着*“创建一个最小的程序” *仅定义了模式你使用,插入一些数据,然后尝试执行你的方法。一旦你这样做,如果问题是可重复的,那么你可以张贴“最小节目”这里的代码,会有人看。通常情况下,创建“最小程序”的过程实际上突出了你的错误。 –