Aggregation $out 阶段创建集合,所有查询返回 TypeError: db.collection.. is not a function

问题描述 投票:0回答:0

我的目标是使用对现有集合的聚合来创建物化视图。我正在关注 this presentation - 探索性分析查询的物化预聚合。有一个附带的Github repo

我已经创建了我的管道,运行它并创建了一个集合。但是,任何在 shell 中针对它运行查询的尝试都会引发错误。

我试过这些方法:

  1. MongoDB Compass 聚合管道构建器
  2. mongosh

两者都创建了一个集合,我通过 Compass UI、Atlas UI 和

mongosh
shell 对其进行了验证。它在运行命令
db.getCollectionNames
getCollectionInfos
时可见,并且在Compass 和Atlas 中都可见。 running db.getCollectionNames() collection info from db.getCollectionInfos

运行

db.stats.findOne()
输出:
TypeError: db.stats.findOne is not a function

这是管道

[
  {
    $addFields:
      {
        processed: {
          $dateFromString: {
            dateString: {
              $replaceOne: {
                input:
                  "$__dc_process.last_updated",
                find: "@",
                replacement: "",
              },
            },
          },
        },
      },
  },
  {
    $sort:
      {
        processed: -1,
      },
  },
  {
    $group:
      {
        _id: {
          campaign: "$_projectId",
          bot: "$bot",
          "render-status": "$render-status",
          "stream-status": "$stream.status",
          processor: "$__dc_process.satellite",
        },
        "total": {
          $count: {},
        },
        "last_updated": {
          $first: "$processed",
        },
        "last_updated_job": {
          $first: "$$ROOT",
        },
      },
  },
  {
    $out: "stats",
  },
]

我试过断开并重新连接外壳。在 Compass 和 Atlas 的 UI 中,查询确实有效并返回结果,但我无法在 shell 中复制。

我不太确定

group
阶段不是第一个这个事实是否有任何影响?演示者指出你不应该事先做任何过滤,但我没有在这里做。

有什么建议吗?

mongodb aggregation-framework mongodb-atlas mongo-shell mongodb-compass
© www.soinside.com 2019 - 2024. All rights reserved.