问题
How do I write an $in
query along with aggregate in mongoDB? I want to write an equivalent mongoDB query for the SQL below
SELECT name,count(something) from collection1
where name in (<<list of Array>>) and cond1 = 'false'
group by name
回答1:
The equivalent mongo query follows:
db.collection1.aggregate([
{ "$match": {
"name": { "$in": arrayList },
"cond1": "false"
} },
{ "$group": {
"_id": "$name",
"count": { "$sum": "$something" }
} }
])
来源:https://stackoverflow.com/questions/41034143/mongodb-in-with-aggregate-query