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 d171bf1..767ff41 100644 --- a/getMongoData/getMongoData.js +++ b/getMongoData/getMongoData.js @@ -229,11 +229,11 @@ 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 { - throw("Error running '" + command + "': " + err); + throw new Error("Error running '" + command + "': " + err); } } endTime = new Date(); @@ -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 @@ -503,6 +505,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( { @@ -578,6 +582,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;