I have a hard time believing this question hasn\'t been asked and answered somewhere already, but I can\'t find any trace of it.
I have a MongoDB aggregation query t
I solved the same problem just last night, this way:
> db.test.aggregate({$group:{_id:{$gt:["$field", null]}, count:{$sum:1}}})
{ "_id" : true, "count" : 2 }
{ "_id" : false, "count" : 2 }
See http://docs.mongodb.org/manual/reference/bson-types/#bson-types-comparison-order for a full explanation of how this works.