2016-01-18 39 views
7
db.movieDetails.updateMany({ 
    "tomato.consensus": null, 
    "imdb.votes":{$lt:10000}, 
    "year":{$gte:2010,$lte:2013}}, 
    { 
     $unset:{"tomato.consensus":"" 
    } 
}) 

當我在mongo shell中鍵入上面的命令時,收到一個錯誤,指出updateMany不是一個有效的函數。mongodb的'updateMany'函數是否被棄用?

TypeError: Property 'updateMany' of object video.movieDetails is not a function at (shell):1:17

我檢查了文檔,updateMany列出了一個有效的函數。我想知道爲什麼我收到錯誤。

回答

5

updateMany命令尚未被棄用。你會在這裏找到命令的文檔:db.collection.updateMany

您無法使用該命令,因爲它是在3.2版本的MongoDB中引入的。您需要安裝3.2版本才能使用updateMany命令。

+0

謝謝,我使用的是3.0.2 :( –

+5

從我閱讀文檔'update'使用'multi'標誌應該做同樣的事情'updateMany'。這是真的嗎? – matth

+0

@matth如果您正在使用monogdb 2.2然後 db.test.update({foo:「bar」},{$ set:{test:「success!」}},{multi:true}) – Nitin