MongoDB `count` returns less then number of entities in `find` result

88 views Asked by At

My test looks like

> db.MyCollection.count()
8
> db.MyCollection.find()
{ "_id" : ObjectId("58f5cfc65faf1122b63dca3f"), /* ... */ }
{ "_id" : ObjectId("58f5cfc65faf1122b63dca40"), /* ... */ }
{ "_id" : ObjectId("58f5ebc95faf11638526d743"), /* ... */ }
{ "_id" : ObjectId("58f5eecb5faf1163872f95a3"), /* ... */ }
{ "_id" : ObjectId("58f5ef605faf11638526d745"), /* ... */ }
{ "_id" : ObjectId("58f5f0505faf1161595c1a35"), /* ... */ }
{ "_id" : ObjectId("58f5f0ca5faf1163872f95a4"), /* ... */ }
{ "_id" : ObjectId("58f5f48e5faf11638526d746"), /* ... */ }
{ "_id" : ObjectId("58f5f4e05faf1161595c1a38"), /* ... */ }
{ "_id" : ObjectId("58f5f5625faf1163872f95a7"), /* ... */ }
{ "_id" : ObjectId("58f5f5855faf11638526d749"), /* ... */ }
{ "_id" : ObjectId("58f5f6825faf1161595c1a3b"), /* ... */ }
{ "_id" : ObjectId("58f5f6ca5faf1163872f95aa"), /* ... */ }
{ "_id" : ObjectId("58f5f6e65faf11638526d74c"), /* ... */ }
{ "_id" : ObjectId("58f5f6e75faf1161595c1a3c"), /* ... */ }
{ "_id" : ObjectId("58f5f6e95faf1163872f95ab"), /* ... */ }
{ "_id" : ObjectId("58f5f76f5faf1161595c1a3d"), /* ... */ }
{ "_id" : ObjectId("58f5f8685faf1163872f95ac"), /* ... */ }
{ "_id" : ObjectId("58f600de5faf1163872f95be"), /* ... */ }
Type "it" for more
> db.MyCollection.count()
8

How is it possible? I've tried to reindex, but nothing helps. I'm using Wired Tiger storage engine and no sharding/replication.

1

There are 1 answers

1
Grigorii Sokolik On

db.MyCollection.validate() helps for me!