1

I have a mongo collection. when I run

> db.coll.count()
6570
>> db.coll.aggregate({ "$group" : { "_id": null, "total": { $sum : 1 } }} )
{ "_id" : null, "total" : 6575 }

why the result is different?

ragusa
  • 21
  • 2
  • Possible duplicate of [mongo:the return don't equal count()](http://stackoverflow.com/questions/39698862/mongothe-return-dont-equal-count) – styvane Jan 19 '17 at 09:41
  • Also see: [Difference between count() and find().count() in MongoDB](http://stackoverflow.com/questions/32666330/difference-between-count-and-find-count-in-mongodb) – styvane Jan 19 '17 at 09:43

1 Answers1

-2

Why don't you dig a bit deeper to find the inconsistency

db.coll.find({},{_id:1}).toArray().length;

verses

db.coll.aggregate({ "$group" : { "_id": null, "ids": { $push : $_id }}},{$project : {_id:0, count : {$size:"$ids"}} )

That way you can see if there is some extra _ids . If both are consistent in terms of ids.

Rahul Kumar
  • 2,781
  • 1
  • 21
  • 29