2016-12-08 120 views
0

如何在mongoDB中編寫$in查詢以及聚合?我想寫的SQL等效MongoDB的查詢下面

SELECT name,count(something) from collection1 
where name in (<<list of Array>>) and cond1 = 'false' 
group by name 

回答

0

等效蒙戈查詢如下:

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