每天,我收到一份文件(更新).我想要做的是插入每个尚不存在的项目.
我正在使用Python驱动程序(pymongo).
我目前做的是(伪代码):
for each document in update:
existing_document = collection.find_one(document)
if not existing_document:
document['insertion_date'] = now
else:
document = existing_document
document['last_update_date'] = now
my_collection.save(document)
Run Code Online (Sandbox Code Playgroud)
我的问题是它非常慢(少于100 000条记录需要40分钟,而且我在更新中有数百万条记录).我很确定有内置的东西可以做到这一点,但更新()的文件是mmmhhh ....有点简洁....(http://www.mongodb.org/display/DOCS/Updating)
有人可以建议如何更快地做到这一点?