【问题标题】:The aggregation pipeline is not enabled for this account此帐户未启用聚合管道
【发布时间】:2021-04-01 17:22:05
【问题描述】:

我尝试通过 Node.js 应用程序针对 Azure Cosmos DB API for MongoDB 执行 mongoDB 聚合管道。我使用版本为3.6.2mongodb 包连接到云资源。

虽然管道在 Azure 门户中运行没有任何错误,但我在 Node 环境中遇到了错误。

MongoError:未为此帐户启用聚合管道。详情请见https://aka.ms/mongodb-aggregation

链接的资源似乎已过时,因为提到的 Azure 门户条目不再存在。

(我的管道包含一个$group 表达式。没有$group,它会返回一个结果。)

我猜,这个问题与我的客户端设置有关,因为它在 Mongo Shell 中运行。

async function aggregate<T>(pipeline: Record<string, unknown>[]): Promise<T[]> {
  const client = await MongoClient.connect(COSMOSDB_URL), {
    useUnifiedTopology: true,
    auth: { user: COSMOSDB_ACCOUNT_NAME, password: COSMOSDB_PASSWORD }
  });
  try {
    // Returns the error
    return await client.db().collection('coll').aggregate<T>(pipeline).toArray();
  } finally {
    await client.close();
  }
}

您有什么建议,如何解决这个问题?

【问题讨论】:

标签: node.js mongodb azure azure-cosmosdb azure-cosmosdb-mongoapi


【解决方案1】:

事实证明,传递给MongoClient.connect()url 与Azure 门户中的连接字符串 不同。

// Returns error "The aggregation pipeline is not enabled for this account". 
const COSMOSDB_URL = `mongodb://${account_name}.documents.azure.com:10255/${database_name}`;

// Correct URL taken from the Connection String (HOST) in the Azure Portal
const COSMOSDB_URL = `mongodb://${account_name}.mongo.cosmos.azure.com:10255/${database_name}`;

db().collection().find() 对两个 URL 都有效,db().collection().aggregate() 仅对第二个有效。

最后我在 Azure 文档中找到了正确的命名规则,其中有一个额外的部分 - Azure Cosmos DB's API for MongoDB (3.6 version): supported features and syntax

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-02
    • 2015-04-24
    • 2020-09-20
    • 2021-04-05
    • 2013-03-14
    • 2021-06-29
    相关资源
    最近更新 更多