Skip to content

Commit

Permalink
Make system collections analyzing optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean Canazzi committed Jul 1, 2020
1 parent 23e6b88 commit 37ad109
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ const optionDefinitions = [
{
name: 'dont-follow-fk', alias: 'n', multiple: true, type: String,
},
{
name: 'include-system', alias: 's', type: Boolean, defaultValue: false,
},
];

const args = commandLineArgs(optionDefinitions);
Expand All @@ -39,6 +42,7 @@ const printUsage = function () {
console.log('\t\t-r, --raw\tShows the exact list of types with frequency instead of the most frequent type only.');
console.log('\t\t-l, --limit\tChanges the amount of items to parse from the collections. Default is 100.');
console.log("\t\t-n, --dont-follow-fk string\tDon't follow specified foreign key. Can be simply \"fieldName\" (all collections) or \"collectionName:fieldName\" (only for given collection).");
console.log("\t\t-n, --include-system string\tAnalyzes system collections as well.");
console.log('');
console.log('Enjoy! :)');
console.log('');
Expand Down Expand Up @@ -110,6 +114,7 @@ const opts = {
raw: args.raw,
limit: args.limit,
dontFollowFK,
includeSystem: args['include-system'],
};

(async () => {
Expand Down
8 changes: 8 additions & 0 deletions extract-mongo-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,14 @@ const getSchema = async (url, opts) => {
}
}

if (!opts.includeSystem) {
for (let i = collectionInfos.length - 1; i >= 0; i--) {
if (collectionInfos[i].name.startsWith('system.')) {
collectionInfos.splice(i, 1);
}
}
}

await Promise.all(collectionInfos.map(async (collectionInfo, index) => {
collections[collectionInfo.name] = {};
schema[collectionInfo.name] = {};
Expand Down

0 comments on commit 37ad109

Please sign in to comment.