I try to execute a mongoDB aggregation pipeline against Azure Cosmos DB API for MongoDB via a Node.js application. I use the mongodb
package with version 3.6.2
to connect to the cloud ressource.
While the pipeline runs without any error in the Azure Portal, I got an error within the Node environment.
MongoError: The aggregation pipeline is not enabled for this account. Please see https://aka.ms/mongodb-aggregation for details.
The linked resource seems outdated, because the mentioned Azure Portal entries don't exist anymore.
(My pipeline contains a $group
expression. Without the $group
, it returns a result.)
I guess, the problem is related to my client setup, since it works within the 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();
}
}
Do you have any suggestions, how to fix the issue?