javascript - 使用 mongoose 5.x 按条件和 groupby 外键查找
问题描述
我正在尝试查询一个集合,我只想要满足 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});
});
解决方案
推荐阅读
- spring - 有没有人将 Spring Security 从 3.1.2 迁移到 5.1.4
- coq - 定理蕴涵的coq语法
- ruby - 基于 Chef 版本的 Cookbook 依赖项
- javascript - 是否可以检测网络应用程序上的 android 后退按钮?
- sql - 如何在不影响生产数据库的情况下生成1000万行表的CSV文件?
- php - 在 laravel 中为接收部分交付的产品创造条件
- deep-learning - 了解何时在 Pytorch 中使用 python 列表
- flutter - 弹出和推送动态路由在 Flutter 中不起作用
- javascript - 使 Div 在可滚动溢出中集中并可见
- sqlite - 这是否正确标准化?