gpt4 book ai didi

MongoDB 集合计数返回 -1

转载 作者:行者123 更新时间:2023-12-04 03:02:32 25 4
gpt4 key购买 nike

我有一个 MongoDB 集合,它在我调用 db.collection.count() 时返回 -1 ,但是如果我调用 db.collection.find()然后返回一份文件。

负数是否表明集合有问题?我在文档中找不到任何内容。

我尝试在集合中插入一个虚拟文档 - 这将计数更改为 2。删除此文档后,计数现在处于正确的 1 值,并且只存储了原始文档。

最佳答案

看来我错过了文档的这一部分:

After an unclean shutdown of a mongod using the Wired Tiger storage engine, count statistics reported by count() may be inaccurate.

The amount of drift depends on the number of insert, update, or delete operations performed between the last checkpoint and the unclean shutdown. Checkpoints usually occur every 60 seconds. However, mongod instances running with non-default --syncdelay settings may have more or less frequent checkpoints.

Run validate on each collection on the mongod to to restore the correct statistics after an unclean shutdown.



运行 db.unboundCollection.validate({full:true})解决了这个问题。

关于MongoDB 集合计数返回 -1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47867570/

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