【发布时间】:2019-03-27 05:11:02
【问题描述】:
我已经编写了以下代码,用于根据我的要求聚合数据。当我在 robo 3t 中尝试时,这很有效。下面的代码有什么问题。它给出了错误,因为“参数必须是聚合管道运算符”。
db.model('KeywordRanking').aggregate([
{
$match: {
user: req.user._id
}
},
{
$project: {
"keyword": 1,
"user": 1,
"website": 1,
"rank": 1,
"type": 1,
"createdDateStr": 1
}
},
{
$lookup: {
from: "keywords",
localField: "keyword",
foreignField: "_id",
as: "keyword_refs"
}
},
{ $unwind: "$keyword_refs" },
{
$group: {
"_id": { "keyword": "$keyword", "website": "$website" },
"website": { "$first": "$website" },
"user": { "$first": "$user" },
"type": { "$first": "$type" },
"ranks": { "$push": { "createdDateStr": "$createdDateStr", "rank": "$rank" } },
"keyword_refs": { "$addToSet": "$keyword_refs" }
}
},
{ $limit: count },
{ $skip: skip }
], { allowDiskUse: true });
【问题讨论】:
标签: node.js mongodb mongoose aggregation-framework