如何将对象转换为MongoDB中的数组?

发布于 2025-01-26 10:03:25 字数 1047 浏览 2 评论 0原文

我正在尝试进行减少,以下片段是我现在拥有的:

 $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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文