Why is the count of collection documents in MongoDb mode decreasing

I have a mongo shard cluster with three shards and all operations on that db are equal to find

or update

(with upsert = true). This means the collection count will increase, but when the counter for collection ( db.mycollection.find().count()

) increases to 80,000,000 or more, I found that sometimes it is incresing, but sometimes it decreases, why? I promise there is no delete action on this db.

I use db.myCollection.getShardDistribution()

to show the distribution, and it shard2

is only 29%, which is less than average.

Here is the trend count:

mongos> db.myCollection.find().count()
84374837
mongos> db.myCollection.find().count()
84375036
mongos> db.myCollection.find().count()
84409281
mongos> db.myCollection.find().count()
84408921
mongos> db.myCollection.find().count()
84407190
mongos> db.myCollection.find().count()
84407173
mongos> db.myCollection.find().count()
84407013
mongos> db.myCollection.find().count()
84406911

      

+3


source to share


1 answer


I'd bet this is a short in action. This is how it works:

  • All documents are split into virtual chunks
  • Tsanks can move between the shards
  • When the balancer moves a piece, it

    1) Copies all documents from this fragment to a new shard

    2) Transfer ownership of the piece to a new shard

    3) Removes documents from the old shard.



Again, this is just a guess based on the information provided. But since you swear there are no deletes in your application, then it should be.

+1


source







All Articles