testResults.aggregate([
{ $match: { testId: { "$exists": true } } },
{ $sort: { _id: -1 } },
{
$group: {
_id: "$testId",
testDetails: {
$push: {
result: "$result",
testName: "$testName"
}
}
}
},
{
$addFields: {
testDetails: { $slice: ["$testDetails", 30] }
}
}
])
.exec(function (err, testResults) {
if (err) res.send(err);
res.json(testResults);
});
使用这个聚合方法,我正在获取最近的30个文档。现在,我需要忽略从获取时起插入时间不到5分钟的文档。在$match aggregate中,如何实现这一点,或者是否有其他方法?
转载请注明出处:http://www.0591kyj.com/article/20230526/2209658.html