[英]Mongodb cursor inconsistent behavior
I have a collection with over a billion documents. 我有超过十亿个文档的集合。 When I iterate over them with the cursor and do some processing, I don't get all the docs.
当我用游标遍历它们并进行一些处理时,我没有得到所有文档。 However, if I just iterate over the collection and count, it does return the right count.
但是,如果我只是遍历集合并计数,它的确会返回正确的计数。
double c = 0;
while(cursor.hasNext){
DBObject entity = entities.next();
//do something
c+=1
}
assert(c==446642690.0)
The assertion fails unless I don't do anything and simply count. 除非我不做任何事情并且简单地计数,否则断言将失败。
Are you doing updates or deletes during your processing? 您在处理过程中要进行更新还是删除? If that is the case you are running into the issue that a mongo cursor is not isolated from updates/inserts during its lifetime.
如果是这种情况,那么您会遇到一个问题,即在其生命周期内,mongo游标没有与更新/插入隔离。 You can partially avoid that behaviour with the snapshot mode but it's really limited.
您可以使用快照模式部分避免这种行为,但确实有其局限性。 See the mongo documentation under cursor isolation for more information about this issue.
有关此问题的更多信息,请参阅游标隔离下的mongo文档 。 As mongo is designed to work this way I think you need to find a way to deal with the situation.
由于mongo被设计为以这种方式工作,因此我认为您需要找到一种处理这种情况的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.