Using $$ROOT in aggregation order

前端 未结 1 1538
隐瞒了意图╮
隐瞒了意图╮ 2021-01-08 00:05

I\'m try get data from collection with some order:

db.data.aggregate([
    {$limit: 1000},
    {$group: {
        _id: \"$service\",
        count: {$sum: 1}         


        
相关标签:
1条回答
  • 2021-01-08 00:33

    So per the comment you need a MongoDB version 2.6 do do this. But of course using 2.6 this works for me:

    db.collection.aggregate([
        { "$limit": 1000 }, 
        { "$group": { 
            "_id": null, 
            "count": { "$sum": 1}, 
            "data": { "$push": "$$ROOT"  }
        }}
    ])
    
    0 讨论(0)
提交回复
热议问题