I have a collection named rice. Im making a pipeline to group and count the number of rice based on average from two places. Next I am calculating based on the following:
- It has several sizes if the size under 3, it will be in the 1st group and the number of rice counted.
- If the size is 3 and below 10, it will in second group and the number of rice counted.
- If the size is 10 and above, it will in third group and the number of rice counted. I have used the code in the following :
db.rice.aggregate([
{ $group: { _id: ["0","3","10"],
rice_title_avg_rice_size: {
"tittle": {$title},
"average_size": {$avg:["$size_A","$size_B"]},
num_rice: {$count: {}
}
}
}
{"_id.1":{$lt:3}, "_id.2":{$gte:3, $lt:10 }, "_id.3":{$gt:10}}
},
{ $sort: { _id: -1 } }
])