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?
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?
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.