It is still in Preview, You need to create a request using the form mentioned in the documentation https://learn.microsoft.com/en-us/azure/cosmos-db/mongodb/vcore/change-streams?tabs=javascript%2CInsert.
How to open this service? Can you attach the picture?(Change Stream on vCore-based Azure Cosmos DB for MongoDB (Preview))
When I use the change stream feature of mongodb in cosmos, it fails. How can I make mongodb in cosmos support this feature?
// ChangeStreamExample.js
const { MongoClient } = require("mongodb");
const uri = "xxxxxx";
async function run() {
const client = new MongoClient(uri, { useNewUrlParser: true, useUnifiedTopology: true });
try {
await client.connect();
const database = client.db("tao-zhang");
const collection = database.collection("test01");
const changeStream = collection.watch();
while (await changeStream.hasNext()) {
const change = await changeStream.next();
const data = {
operationType: change.operationType,
namespace: change.ns.db + "." + change.ns.coll,
documentKey: change.documentKey,
resumeToken: change._id,
fullDocument: change.fullDocument,
wallTime: change.clusterTime
};
console.log(JSON.stringify(data, null, 4));
}
} catch (e) {
console.error("Error processing change stream:", e);
} finally {
await client.close();
}
}
run();
error:
(node:3212484) [MONGODB DRIVER] Warning: useNewUrlParser is a deprecated option: useNewUrlParser has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version
(Use node --trace-warnings ...
to show where the warning was created)
(node:3212484) [MONGODB DRIVER] Warning: useUnifiedTopology is a deprecated option: useUnifiedTopology has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version
Error processing change stream: MongoServerError: Stage $changeStream is not supported yet in native pipeline
at Connection.sendCommand (/home/hanh/data/zhangtao/genai-retrieval-database/examples/node_modules/mongodb/lib/cmap/connection.js:298:27)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async Connection.command (/home/hanh/data/zhangtao/genai-retrieval-database/examples/node_modules/mongodb/lib/cmap/connection.js:326:26)
at async Server.command (/home/hanh/data/zhangtao/genai-retrieval-database/examples/node_modules/mongodb/lib/sdam/server.js:167:29)
at async AggregateOperation.executeCommand (/home/hanh/data/zhangtao/genai-retrieval-database/examples/node_modules/mongodb/lib/operations/command.js:76:16)
at async AggregateOperation.execute (/home/hanh/data/zhangtao/genai-retrieval-database/examples/node_modules/mongodb/lib/operations/aggregate.js:87:16)
at async tryOperation (/home/hanh/data/zhangtao/genai-retrieval-database/examples/node_modules/mongodb/lib/operations/execute_operation.js:207:20)
at async executeOperation (/home/hanh/data/zhangtao/genai-retrieval-database/examples/node_modules/mongodb/lib/operations/execute_operation.js:75:16)
at async ChangeStreamCursor._initialize (/home/hanh/data/zhangtao/genai-retrieval-database/examples/node_modules/mongodb/lib/cursor/change_stream_cursor.js:81:26)
at async ChangeStreamCursor.cursorInit (/home/hanh/data/zhangtao/genai-retrieval-database/examples/node_modules/mongodb/lib/cursor/abstract_cursor.js:632:27) {
errorLabelSet: Set(0) {},
errorResponse: {
ok: 0,
errmsg: 'Stage $changeStream is not supported yet in native pipeline',
code: 115,
codeName: 'CommandNotSupported'
},
ok: 0,
code: 115,
codeName: 'CommandNotSupported'
}
1 answer
Sort by: Most helpful
-
Sajeetharan 2,261 Reputation points Microsoft Employee
2025-02-21T04:51:53.6133333+00:00