2017-11-11 202 views
-1

我想檢查其他'集'是否有我想要添加的值。如果另一組具有該值,則將其從該組中移除並將其添加到新組。 { "_id": "5a052785aa06c22429717bad", "word": "wordtest5", "__v": 0, "pronunciations": [ { "pronunciation": "wordtest1", "_id": "5a052785aa06c22429717bae", "likes": [ "remove_this", "5a0508cfcf4f6620786a3cb1" ], "rating": 1 }, { "pronunciation": "wordtest5", "_id": "5a0674c1053ae929db3a576c", "likes": [], "rating": 1 }, { "pronunciation": "testing5", "_id": "5a06770346be3d2ac6f31561", "likes": [ "remove_this", "5a0508cfcf4f6620786a3cb1", ], "rating": 1 } ] }

我想刪除每個'likes'數組中的所有'remove_this'字符串。

回答

0

使用$關於你提到的其他「套」拉和您要添加的實際設置使用$ addToSet。這樣你就可以實現你想要的。

下一次,請對你的問題非常清楚。

+0

嗨,我發佈了一個例子,並嘗試了'Word.findOneAndUpdate({word},{$ pull:{'pronunciations':{'likes':userId}}},{multi:true})'但不能讓它去除元素。 – earthyearth

相關問題