【发布时间】:2021-04-01 17:22:05
【问题描述】:
我尝试通过 Node.js 应用程序针对 Azure Cosmos DB API for MongoDB 执行 mongoDB 聚合管道。我使用版本为3.6.2 的mongodb 包连接到云资源。
虽然管道在 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();
}
}
您有什么建议,如何解决这个问题?
【问题讨论】:
-
似乎与 azure-docs 存储库中描述的类似问题 - github.com/MicrosoftDocs/azure-docs/issues/45723
标签: node.js mongodb azure azure-cosmosdb azure-cosmosdb-mongoapi