本文介绍了如果给出查询,MongoDB的count()不正确地返回0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的数据库目前正在运行,一切似乎都很好。我想做一些统计,所以我做了一些标准电话。基本上我想要一些特定数据的数量。

Our database is currently running and everything seems to fine. I wanted to do some statistics so I did some standard calls. Basically I wanted the number of some specific data.

首先一些基本的调用,显示数据库中实际上有数据。

First some basic calls to show you that there actually is data in the database.

> db.files.count()
814639

> db.files.find({"migrated":true})
{ "migrated" : true, "filename" : "bleh",... }
...

很清楚有数据,调用返回它。现在我想知道有多少结果,但我得到这个:

So clearly there's data, and the call returns it. Now I want to find out how many results there is, but I get this:

> db.files.count({"migrated":true})
0

也是这样:

> db.files.find({"migrated":true}).count()
0

有谁知道为什么会发生这种情况?

Is there anyone who has any idea why this could be happening?

版本是:

> db.version()
1.8.1

任何帮助将非常感谢

推荐答案

过了一会儿,但我现在关闭了。但它是一个损坏的数据库。必须手动将所有项目从一个数据库移动到一个新的数据库,因为备份停止时,它发现损坏的数据,后来有效的数据没有备份。

Been a while, but I'm closing this now. But it was a corrupt database. Had to manually move all the items from one database to a new one since a backup stopped when it found the corrupt data, and valid data afterwards wasn't being backed up.

这篇关于如果给出查询,MongoDB的count()不正确地返回0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 23:55