[
{
"_id": "1f154439638e97330137f2475dec9ffc",
"title": "1",
"remarks": [
{
"remarktime": "2022/12/06 14:13:12",
"id": 1670307282722
},
{
"remarktime": "2022/12/06 13:00:10",
"id": 1670302838410
},
{
"remarktime": "2022/12/06 12:58:19",
"id": 1670302752430
},
{
"remarktime": "2022/12/06 12:49:31",
"id": 1670302182764
},
{
"remarktime": "2022/12/06 12:49:09",
"id": 1670302197960
},
{
"id": 1670298287375,
"remarktime": "2022/12/06 11:43:50"
}
]
},
{
...
}
]
只想取得remarks的前三个怎么做?
https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/command/aggregate/AggregateCommand.slice.html
已搞定
db.collection('Program').aggregate() .match(_.and([{ valid: true }])) .project({ remarks: 1,_id:0 }) .unwind({ path:'$remarks' }) .replaceRoot({ newRoot: $.mergeObjects('$remarks') }) .sort({pldzs:-1}) .limit(3) .end()