我试图在我的MongoDB上运行一些更新操作。我想使用指定的大容量更新操作here,但是使用pymongo这对我不起作用。我的代码如下
import pymongo
client = pymongo.MongoClient()
db = client.test
bulk = db.testCol.initialize_unordered_bulk_op();
bulk.find({"_id":"1,1,1"}).update({"$set":{"attr1":1, "attr2":"X", "attr3":99}})
print bulk.execute()
其输出为:
^{pr2}$据我所知,Mongo正在查找文档(nMatched=1),但没有更新它(nModified=0)。我不明白它为什么这么做。在
当我在不使用Bulk的情况下手动执行操作时,输出似乎是正确的,并且记录会根据请求进行修改。 代码:
import pymongo
client = pymongo.MongoClient()
db = client.test
print db.testCol.update({"_id":"1,1,1"}, {"attr1":1, "attr2":"X", "attr3":99})
这样做是可行的,无论是打印还是数据库的内容。在
{'updatedExisting': True, u'nModified': 1, u'ok': 1, u'n': 1}
我不知道我做错了什么。据我所知,我遵循了执行批量更新的正确过程。在
我创建了一个实用函数来进行批量更新。在
例如,假设
test
数据库中的myCollection
集合需要更新为y=3,其中x=1,y=6,x=5。在那么对实用函数的调用如下所示
^{pr2}$相关问题 更多 >
编程相关推荐