mongoDb $ in与聚合查询 [英] mongoDb $in with aggregate query

查看:395
本文介绍了mongoDb $ in与聚合查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在mongoDB中编写一个$in查询以及聚合?我想为下面的SQL写一个等效的mongoDB查询

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

推荐答案

等效的mongo查询如下:

The equivalent mongo query follows:

db.collection1.aggregate([
    { "$match": { 
        "name": { "$in": arrayList },
        "cond1": "false"
    } }, 
    { "$group": {
        "_id": "$name",
        "count": { "$sum": "$something" }
    } }
])

这篇关于mongoDb $ in与聚合查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆