mongoDb $in with aggregate query

╄→гoц情女王★ 提交于 2019-12-12 14:08:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!