How can i retrieve modified documents after an upd

2019-02-23 14:54发布

I'm using an update operation with upsert. I want to retrieve all documents that have been modified after an update.

for key in categories_links:
    collection.update({"name" : key}, {"name": key ,"url" : categories_links[key]}, True)

2条回答
你好瞎i
2楼-- · 2019-02-23 15:36

You should use a timestamp field in your documents if you ever need to find which ones where updated and when. There is a BSON type for that.

查看更多
我命由我不由天
3楼-- · 2019-02-23 15:49

To my knowledge, pymongo will not return a list of all of the records which have been modified by an update.

However, if you are using a replicaset, you might be able to accomplish this by looking at the oplog.

According to the documentation:

The oplog must translate multi-updates into individual operations in order to maintain idempotency. This can use a great deal of oplog space without a corresponding increase in data size or disk use.

If you want to keep track of each element being updated, you might instead do a find(), and then loop through those to do an individual update() on each. Obviously this would be much slower, but perhaps a tradeoff for your specific use case.

查看更多
登录 后发表回答