3
可能重複:
In MongoDB, How to toggle a boolean field in one document with atomic operation?「切換」 查詢
我需要更新文件的價值, 「切換」 是:
的集合 「註釋」其布爾標誌爲「isAdmin」。
我要更新給定的評論ID,如果isAdmin爲false,並且反之亦然,則將其設置爲false。
但是這不起作用:
db.comments.update({ "id": "xxx" }, { $set: { isAdmin: $not isAdmin } });
什麼是正確的語法?
這可能幫助:http://stackoverflow.com/questions/9459789/in-mongodb-how-to-toggle-a-boolean-field-in-one-document-with-原子操作 – DhruvPathak