hi
i use c# driver to monitor the changestream for all dbs except for system dbs, but not work, code as below:
var pipeline = new EmptyPipelineDefinition<ChangeStreamDocument<BsonDocument>>().Match("{ $or: [ {operationType: 'replace' }, { operationType: 'insert' }, { operationType: 'update' }, { operationType: 'delete' }, { operationType: 'invalidate' } ] }");
var options = resumeTokenStorage != null ? new ChangeStreamOptions { FullDocument = ChangeStreamFullDocumentOption.Default, ResumeAfter = resumeTokenStorage.resumetoken } : new ChangeStreamOptions { FullDocument = ChangeStreamFullDocumentOption.Default };
using (var changeStream = await client.WatchAsync(pipeline, options)) {}
i create below mongo role and previledge
use admin
db.createRole(
{
role: "manageOpRole",
privileges: [
{ resource: { cluster: true }, actions: [ "killop", "inprog" ] },
{ resource: { db: "", collection: "" }, actions: [
"bypassDocumentValidation",
"changeCustomData",
"changePassword",
"changeStream",
"collMod",
"collStats",
"compact",
"convertToCapped",
"createCollection",
"createIndex",
"createRole",
"createUser",
"dbHash",
"dbStats",
"dropCollection",
"dropDatabase",
"dropIndex",
"dropRole",
"dropUser",
"emptycapped",
"enableProfiler",
"enableSharding",
"find",
"getShardVersion",
"grantRole",
"indexStats",
"insert",
"killCursors",
"listCollections",
"listIndexes",
"moveChunk",
"planCacheIndexFilter",
"planCacheRead",
"planCacheWrite",
"reIndex",
"remove",
"renameCollectionSameDB",
"repairDatabase",
"revokeRole",
"setAuthenticationRestriction",
"splitChunk",
"splitVector",
"storageDetails",
"update",
"validate",
"viewRole",
"viewUser"
] }
],
roles: []
}
)
use admin
db.grantRolesToUser("admin", ["manageOpRole"])
but when i start to monitor all dbs’ changestream, it report below exception:
Command aggregate failed: not authorized on admin to execute command { aggregate: 1, pipeline: [ { $changeStream: { allChangesForCluster: true } }, { $match: { $or: [ { operationType: “replace” }, { operationType: “insert” }
what should i do some setting for it? thanks.