user3892260
user3892260

Reputation: 1035

MongoDB count() mismatch on a sharded cluster

I have loaded a collection consisting of 24,895,212 elements into MongoDB. I have sharding enabled with 5 shards. The data is evenly sharded across the 5 shards. The Balancer is not running currently (sh.isBalancerRunning() returns false).

Based on the documentation, once the balancer completes sharding, I should be able to run the db.collection.count() command to get a row count. However if I do that I get 25,245,767 rows. Not sure where the extra 350,555 rows are coming from. Note that if I run the command:

mongos>  db.collection.find({}).itcount()

I get the correct count of 24,895,212 but the problem is that this command runs for about 15 minutes...

Any ideas on where I am going wrong, why i have the 350,555 row diff? I also tried to run the orphan cleanup process by issuing the command:

mongos> db.runCommand( { cleanupOrphaned: "<db>.<collection>" } )

However this process ran for about 9 hours over night and didn't finish in the morning...

Upvotes: 2

Views: 769

Answers (1)

vmr
vmr

Reputation: 1935

Since cleaning up orphan documents(caused due to failed migrations) did not complete it is quite possible they still exist. Moreover there is a open bug: Sharded collection counts (on primary) can report too many results

This bug is due to be fixed in 2.7. I think you are facing the same issue.

Upvotes: 2

Related Questions