mongo聚合命令

db.getCollection('chat').aggregate([
{
"$match": {
"last": 1,
"type": 0
}
},
{
$project:{giftId:1,text:1,userId:1,createAt:1}
},
{
$group:{
_id:'$giftId',
createAt:{$max:'$createAt'},
text:{$last:'$text'},
userId:{$last:'$userId'},
}
}
])

猜你喜欢

转载自www.cnblogs.com/yzf666/p/9618198.html