From a5bea29792cfa1bfacd019d522dacfd61a30cacb Mon Sep 17 00:00:00 2001 From: Bart Polot Date: Wed, 21 Aug 2024 17:51:20 +0200 Subject: [PATCH 1/4] Skip indexes on the local database, since even with the atlasAdmin role (or [backup, clusterMonitor, readAnyDatabase]) it fails on Atlas clusters with: MongoServerError: not authorized on local to execute command { aggregate: "replset.minvalid", pipeline: [ { $indexStats: {} }, { $group: { _id: "$key", stats: { $push: { accesses: "$accesses.ops", host: "$host", since: "$accesses.since" } } } }, { $project: { key: "$_id", stats: 1, _id: 0 } } ], cursor: {}, apiVersion: "1", lsid: { id: UUID() }, $clusterTime: { clusterTime: Timestamp(1724256067, 1), signature: { hash: BinData(0, ), keyId: } }, $db: "local" } --- getMongoData/getMongoData.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/getMongoData/getMongoData.js b/getMongoData/getMongoData.js index d171bf1..4bcedb6 100644 --- a/getMongoData/getMongoData.js +++ b/getMongoData/getMongoData.js @@ -503,6 +503,8 @@ function printDataInfo(isMongoS) { } printInfo('Indexes', function(){return db.getSiblingDB(mydb.name).getCollection(col).getIndexes()}, section, false, {"db": mydb.name, "collection": col}); + if (mydb.name == 'local') + return; printInfo('Index Stats', function(){ var res = db.getSiblingDB(mydb.name).runCommand( { From d88c050290402574267044bd6ca4161e57e272dd Mon Sep 17 00:00:00 2001 From: Bart Polot Date: Wed, 21 Aug 2024 18:11:05 +0200 Subject: [PATCH 2/4] Throw an Error object, since the catch is using e.message to display. --- getMongoData/getMongoData.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/getMongoData/getMongoData.js b/getMongoData/getMongoData.js index 4bcedb6..d36d182 100644 --- a/getMongoData/getMongoData.js +++ b/getMongoData/getMongoData.js @@ -233,7 +233,7 @@ function printInfo(message, command, section, printCapture, commandParameters) { print("Error running '" + command + "':"); print(err); } else { - throw("Error running '" + command + "': " + err); + throw new Error("Error running '" + command + "': " + err); } } endTime = new Date(); From c3d2a9f9f4f7a7e8b9d6f0b4c3aa8cee64b0fb8c Mon Sep 17 00:00:00 2001 From: Bart Polot Date: Wed, 21 Aug 2024 18:15:57 +0200 Subject: [PATCH 3/4] Allow to continue if an error is encounters an error, to allow the tool to run on MongoDB imitators. For instance on DocumentDB this results in: MongoServerError: Feature not supported: getCmdLineOpts MongoServerError: Feature not supported: getParameter MongoServerError: local db creation is not supported MongoServerError: Field 'type' is currently not supported MongoServerError: Profiler (slow query logger) is supported via log exports to Amazon CloudWatch. For more information: https://docs.aws.amazon.com/documentdb/latest/developerguide/profiling.html --- getMongoData/README.md | 5 +++++ getMongoData/getMongoData.js | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/getMongoData/README.md b/getMongoData/README.md index 6842360..ee08134 100644 --- a/getMongoData/README.md +++ b/getMongoData/README.md @@ -32,6 +32,11 @@ execution: mongo --eval "var _printJSON=false;" getMongoData.js > getMongoData-output.log +To run the tool against a database that imitates (but doesn't fully implement) the MongoDB API, it can +help to ignore some errors with the following `eval` option: + + mongo --eval "var _abort_on_error=false;" getMongoData.js > getMongoData-output.log + To have a `mongos` for a sharded cluster output full details of chunk distribution across shards, include `var _printChunkDetails=true` in the `--eval` option: diff --git a/getMongoData/getMongoData.js b/getMongoData/getMongoData.js index d36d182..a1ee6da 100644 --- a/getMongoData/getMongoData.js +++ b/getMongoData/getMongoData.js @@ -229,7 +229,7 @@ function printInfo(message, command, section, printCapture, commandParameters) { } err = null } catch(err) { - if (! _printJSON) { + if (! _printJSON || ! _abort_on_error) { print("Error running '" + command + "':"); print(err); } else { @@ -580,6 +580,7 @@ function printShardOrReplicaSetInfo() { } if (typeof _printJSON === "undefined") var _printJSON = true; +if (typeof _abort_on_error === "undefined") var _abort_on_error = false; if (typeof _printChunkDetails === "undefined") var _printChunkDetails = false; if (typeof _ref === "undefined") var _ref = null; From e957bc820b4b0a6b09649e9068ca854921a37f47 Mon Sep 17 00:00:00 2001 From: Bart Polot Date: Tue, 27 Aug 2024 08:45:23 +0200 Subject: [PATCH 4/4] Fix error with DocumentDB not allowing filtering on getCollectionInfos --- getMongoData/getMongoData.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/getMongoData/getMongoData.js b/getMongoData/getMongoData.js index a1ee6da..767ff41 100644 --- a/getMongoData/getMongoData.js +++ b/getMongoData/getMongoData.js @@ -452,8 +452,10 @@ function printDataInfo(isMongoS) { var collectionNames = [] // Filter out views - db.getSiblingDB(mydb.name).getCollectionInfos({"type": "collection"}).forEach(function(collectionInfo) { - collectionNames.push(collectionInfo['name']); + db.getSiblingDB(mydb.name).getCollectionInfos().forEach(function(collectionInfo) { + if (collectionInfo.type === "collection") { + collectionNames.push(collectionInfo['name']); + } }) // Filter out the collections with the "system." prefix in the system databases