2017-06-20 114 views
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) 
+0

問題尋求幫助調試(**「爲什麼不是這個代碼的工作?」 **)必須包括所期望的行爲,一*特定問題或錯誤,並在最短的代碼必要*在問題本身**中重現它**。沒有**明確問題陳述**的問題對其他讀者無用。 參見:[如何創建最小,完整的,並且可驗證示例](http://stackoverflow.com/help/mcve) –

+0

在這種情況下它意味着*「創建一個最小的程序」 *僅定義了模式你使用,插入一些數據,然後嘗試執行你的方法。一旦你這樣做,如果問題是可重複的,那麼你可以張貼「最小節目」這裏的代碼,會有人看。通常情況下,創建「最小程序」的過程實際上突出了你的錯誤。 –

回答

0

搜索了幾個小時後,我找到了解決方案。問題是,在我用貓鼬的版本,每當選項出現這個錯誤:

runSettersOnQuery: true 

是在架構設置。隨着在Github上的最新版本了這個問題解決