分组查询示例
db.spot_comment.aggregate([
{
$match: {
$or: [{
create_at: {
$eq: '2018-11-24'
}},
{create_at: {
$eq: '2018-11-13'
}
}]
}
},
{
$group: {
_id: {
c_score: "$c_score",
create_at:"$create_at"
},
'count': {
'$sum': 1
}
}
}
])
分组获取最新的一条记录
db.spot_comment.aggregate([
{
$group: {
_id: {
ota_id:"$ota_id",
ota_spot_id:"$ota_spot_id"
},
"time": {
$last: "$create_at"
},
"c_score": {
$last: "$c_score"
}
}
}, {
$sort: {
"create_at": - 1
}
}])
网友评论