mongo 聚合查詢

vx_guanchaoguo0發表於2024-12-05

按照數量返回

db.getCollection("xxxx").aggregate([
  {
    $match: {
      "daily.incomeMap": { $exists: true }
    }
  },
  {
    $group: {
      _id: "$groupId",  
      totalCount: { $sum: 1 }  
    }
  },
  {
    $sort: { totalCount: -1 } 
  },
  {
    $limit: 1000  
  }
])

相關文章