mongodb聚合和推动组

时间:2017-06-08 16:37:39

标签: mongodb

我正在尝试使用$ push在群组聚合中推送具有minSalary的数据。

查询:

db.users.aggregate([
    { $match: { experience: { $gte:3, $lte:10} } },
    { $group: { _id: {totalExperience:"$experience"}, "count": {$sum:1},"minSalary": {$min:"$expected_salary"}, "minUsers": {$push:"$_id"}, "maxSalary": {$max:"$expected_salary"} } },    
    { $sort: { '_id.totalExperience': -1 } }    
])

结果

{
    "_id" : {
        "totalExperience" : 9
    },
    "count" : 549.0,
    "minSalaryCount" : 120000,
    "maxSalary" : 180000
}

我也期待以下结果

  {
    "_id" : {
        "totalExperience" : 9
    },
    "count" : 549.0,
    "minSalaryCount" : 120000,
    "maxSalary" : 180000,
    "minSalaryUsers":[
       ObjectId('5355345345sdrrw234234'),
       ObjectId('5355345345sdeee234234'),
       ObjectId('5355345345sdertw234234')
    ]
}

谢谢。

0 个答案:

没有答案