node.js - 带有一些字段的 mongodb 组并全部推回
问题描述
我有以下收藏
_id:60b8c9294af8f15198249e5b
title:"abcd"
note:"abcdfregh"
date:2021-06-03T12:16:28.598+00:00
User_id:2
createdAt:2021-06-03T12:20:57.261+00:00
updatedAt:2021-06-03T12:20:57.261+00:00
Journal_id:15
__v:0
我正在尝试在日期中对月份和年份进行 $group 并 $push 所有字段
询问:
Upload.aggregate([
{ $match : { User_id : Number(user_id)}},
{ $group : {
_id : { month: { $month : "$date" },year: {$year : "$date"}},
details : {$push : {"title" :"$title","note" : "$note"}}
}},
]),
但我得到这样的输出:
[
{ _id: 'abcd', details: [ [Object], [Object] ] },
{ _id: 'aabghk\tinjcwmdsoi', details: [ [Object] ] }
]
我是 mongodb 的新手,正在努力理解这个错误;
我需要的期望输出是:
预期输出:
[
{ _id: 'abcd', details: [ {title:"title here", note: "note here"}, {title:"title here", note: "note here"} ] },
{ _id: 'aabghk\tinjcwmdsoi', details: [ {title:"title here", note: "note here"} ] }
]
解决方案
推荐阅读
- function - 为什么 Kotlin sortedWith() 不只是取一个函数
- postgresql - 如何在 Postgresql 中将带有多个参数的 ARRAY_AGG 移植到 Snowflake
- python-3.x - Pandas:为“宽”数据集组合行的更好方法?
- c# - 访问 Internet Explorer 下载列表
- scala - 懒惰地遍历函数集合,在第一次成功时短路
- python - DJANGO FORMS.py 'RawQuerySet' 对象没有属性 'all'
- vb.net - 如何为按钮创建键盘快捷键?
- javascript - 如何在 Dynamodb 中存储对象?
- java - 为什么我的控制台在 Eclipse 上打印空白/与背景颜色相同?
- python - SVD 函数返回维度不兼容的矩阵