如何将对象转换为MongoDB中的数组?
我正在尝试进行减少,以下片段是我现在拥有的:
$push: {
$round: {
$divide: [
{ $subtract: [new Date(), "$created_at"] },
86400000
]
}
}
},
prodotti: { $push: "$items" },
ordini: { $sum: 1 }
}
},
{
$project: {
_id: 0,
email: "$_id",
frequency: "$frequency",
monetary: "$monetary",
recency: { $first: "$recency_array" },
average_timing_purchase: { $avg: "$recency_array" }, // purchase average in days
prodotti: {
$reduce: {
input: "$prodotti",
initialValue: [],
in: { $concatArrays: ["$$value", "$$this"] }
}
},
当我运行作业时,它会引发以下错误: planexecutor在汇总过程中::由:: $ confarrays引起的仅支持数组,而不是
我的猜测是因为“ $ prodotti”是一个对象,我尝试了$ objectto array汇总,但我认为我没有得到语法或在哪里使用。
I'm trying to do a reduce, the following snippet is what I have right now:
$push: {
$round: {
$divide: [
{ $subtract: [new Date(), "$created_at"] },
86400000
]
}
}
},
prodotti: { $push: "$items" },
ordini: { $sum: 1 }
}
},
{
$project: {
_id: 0,
email: "$_id",
frequency: "$frequency",
monetary: "$monetary",
recency: { $first: "$recency_array" },
average_timing_purchase: { $avg: "$recency_array" }, // purchase average in days
prodotti: {
$reduce: {
input: "$prodotti",
initialValue: [],
in: { $concatArrays: ["$value", "$this"] }
}
},
When I run the job it throws the following error:
PlanExecutor error during aggregation :: caused by :: $concatArrays only supports arrays, not object
My guess is because "$prodotti" is a object, I tried $objectToArray aggregation but I think I didn't get the syntax or where to use.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论