我正在尝试使用 Change Streams 来查找/监控对 mongo 集合的更改。
cursor = db.collection.watch(full_document='updateLookup')
document = next(cursor)
print document['documentKey']
在使用 updateMany 一次更新多个文档时,我无法看到所有更改的文档。但是,如果我一次更新一个,那么我会在 Stream 中看到每个更改。
db.collection.updateMany( {"contacts.firstName": "XXXXXX"}, { $set: {"LocationId" : 11111} } )
{ "acknowledged" : true, "matchedCount" : 77, "modifiedCount" : 77 }
结果:
{u'_id': ObjectId('580694d039811a468b96fc7b')}
{u'_id': ObjectId('58aeebed39811a468b974e97')}
{u'_id': ObjectId('59efe28b39811a468b97b9cc')}
最佳答案
我想通了这个问题。需要遍历更改流游标以获取所有更新。
while True:
cursor = db.collection.watch(full_document='updateLookup')
while cursor:
print next(cursor)['documentKey']
关于mongodb - Mongodb Change Streams 未将所有更新返回到集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49119203/