假设我想对文档update执行一些简单的e操作,如下所示:
print 'Updating:',e['title'],e['_id']
jp.update(e,{'$set':{'sensesJa':sensesJa,'last':'#pushFormsAndSetNewAtt'},
'$push':{'forms':{'$each':forms_to_push}}})它确实打印了“更新:.”,但是文档没有被更新。有什么想法吗?
更新:添加要点: https://gist.github.com/actor2019/5876903#file-clip-mongodb-pymongo-update-didnt-work-py-L36
发布于 2013-06-26 15:10:53
更新的查询部分与任何文档不匹配,因此没有任何要更新的内容匹配。
正如您所知道的,然后对_id进行查询将确保查询的目标是正确的。
jp.update(e['_id'], {'$set':{'sensesJa':sensesJa,'last':'#pushFormsAndSetNewAtt'},
'$push':{'forms':{'$each':forms_to_push}}})更新
通过一个完整的文档查询是很好的,和,只要有匹配,它就会更新。下面是查询和查找文档的示例:
from pymongo import *
client = MongoClient()
coll = client.test.test
coll.save({'_id': 1, 'hello': 'world'})
e = coll.find_one()
print(e)
coll.find(e).count()输出是1,因为它匹配一个文档。唯一会失败的情况是,如果我更改了e或其他什么东西(另一个进程),在我之间删除了e,第一次和第二次找到它。
https://stackoverflow.com/questions/17317677
复制相似问题