Upsert with $in

大憨熊 提交于 2019-12-06 13:37:41

Certainly does work :

> db.test.save({_id:"a", n:3})
> db.test.update({_id:"b"}, {$inc:{n:1}}, true, false)
> db.test.find()
{ "_id" : "a", "n" : 3 }
{ "_id" : "b", "n" : 1 }

But your example query doesn't use $in so I'm assuming you're actually trying :

{'_id' : {$in:['google', 'Abhishek_Vaid', 'andrew_mason']}, {'$inc' : {'n' : 1} }, upsert=True, multi=True )

and expect it to update or create an entry for each _id value you pass. This will not work if any of the _id values already exists since upsert will only create a new document of no document matches the search criteria.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!