当我在mongodb中扫描一个集合并编辑所有项目时,我得到了这个问题:扫描计数器 i 可以大于 cursor.count()。为什么会这样?任何人都可以弄清楚吗?
db.baiduwords.find().count() = 805280
db.baiduwords.find().size() = 805280
但我去 1498400 或更多。
import pymongo
if __name__=='__main__':
client = pymongo.MongoClient()
i = 0
collection = client.baike.baiduwords.find()
for item in collection:
i += 1
MajorClass = []
for cl in item['C']:
c = cl
while(1):
a = client.baike.baiduclass.find({'s':c})
if a.count():
a = a[0]
if a['f'] == u'Root':
MajorClass.append(c)
break
else:
c = a['f']
else:
break
item['MC'] = list(set(MajorClass))
client.baike.baiduwords.save(item)
if i%100 == 0:
print "%d/%d"%(i, collection.count())
PS:printShardingStatus:这个数据库没有启用分片。