MongoDB aggregate by field exists
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: 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 that needs to group by a boolean: the existence of another field. For example let's start with this collection: > db.test.find() { "_id" : ObjectId("53fbede62827b89e4f86c12e"), "field" : ObjectId("53fbede62827b89e4f86c12d"), "name" : "Erik" } { "_id" : ObjectId("53fbee002827b89e4f86c12f"), "name" : "Erik" } { "_id" : ObjectId("53fbee092827b89e4f86c131"), "field" : ObjectId(