Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix permission errors when running getMongoData.js against Atlas, allow to ignore errors #136

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions getMongoData/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 9 additions & 4 deletions getMongoData/getMongoData.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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( {
Expand Down Expand Up @@ -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;

Expand Down