2016-10-29 58 views
0

我的用戶_id在foundStory.authors數組,像這樣:如何更新_id數組中的所有Mongo文檔?

"authors": [ 
    { 
     "$oid": "5814ef8cafc25327a572eee5" 
    }, 
    { 
     "$oid": "5814ef80afc25327a572eee4" 
    } 
], 

我想通過作者進行陣列運行,並且由兩個增加自己的分數。目前,我想通過以下要做到這一點:

User.update({ _id: { $in: foundStory.authors } },{ $inc: { score : 2 } }) 

但是,這只是增加了筆者我數組的最後一個索引。從我讀過的內容來看,我預計這會奏效。有任何想法嗎?

回答

1

想通了......加入{multi:true}似乎解決了這個問題。

User.update({ _id: { $in: foundStory.authors } },{ $inc: { score : 2 } }, { multi: true }) 
+0

刪除我的答案,因爲這是正確的。 – Paul