gpt4 book ai didi

python - MongoDB 快照

转载 作者:可可西里 更新时间:2023-11-01 10:44:21 27 4
gpt4 key购买 nike

我正在使用 pymongo 从 MongoDB 中插入和检索数据。这两个操作可以同时执行。问题是我什么时候做 rows = db.<collection>.find()在pymongo中,每次rows.count()返回不同的响应(因为数据的插入也在同一时间完成)。有什么方法可以限制 MongoDB 只返回执行 find() 时存在的行吗?陈述?我尝试添加 snapshot=Truefind()但问题仍然存在。

最佳答案

db.<collection>.find().count()无论如何都会对 mongodb 进行额外的 ( runCommand count ) 调用。

简单地获取光标的长度怎么样,就像这样:

rows = db.<collection>.find()
print len(list(rows))

请注意,您不能只使用 len(rows) .

希望对您有所帮助。

关于python - MongoDB 快照,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16365363/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com