Javascript 使用mongoose 5.x按条件查找和按外键分组

Javascript 使用mongoose 5.x按条件查找和按外键分组,javascript,node.js,mongodb,mongoose,Javascript,Node.js,Mongodb,Mongoose,我试图查询一个集合,我只想要满足createdAt条件的结果,然后我想按groupId对这些结果进行分组 我已经尝试使用$match和$group,但是我得到一个错误,说我的foreignKey(groupId)未定义 Call.aggregate([ { $match: { createdAt: { $gte: "2019-04-24T00:00:00.000Z", $lt: "2019-05-01T00:00:00.00

我试图查询一个集合,我只想要满足createdAt条件的结果,然后我想按groupId对这些结果进行分组

我已经尝试使用$match和$group,但是我得到一个错误,说我的foreignKey(groupId)未定义

Call.aggregate([
{
    $match: {
        createdAt: {
            $gte: "2019-04-24T00:00:00.000Z",
            $lt: "2019-05-01T00:00:00.000Z"
        }
    }
},
{
    $group: {
        _id: groupId
    }
}
]).exec().then(result => {

 result.forEach(function (call) {
        console.log(call.createdAt);
    });

return res.status(200).json({
results: result});

});

试试
\u id:'$groupId'
试试
\u id:'$groupId'