Last active
April 29, 2016 16:54
-
-
Save korsmakolnikov/f12d50597aa4215d2c59a11614f89804 to your computer and use it in GitHub Desktop.
Program to scan an entire mongo database for a certain fieldname (and check recursevely in embedded docs)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var collections = db.getCollectionNames(); | |
//print(collections); | |
collections.forEach(function(col) { | |
function isEmpty(obj) { | |
for(var prop in obj) { | |
if(obj.hasOwnProperty(prop)) | |
return false; | |
} | |
return true; | |
} | |
function professioneScan(col) { | |
var result = []; | |
var count = 0; | |
db.getCollection(col).find({}).forEach(function scan(doc) { | |
for(var key in doc) { | |
print(typeof doc[key]); | |
/*if((typeof doc[key]) === 'object') { | |
scan(doc[key]); | |
} else { | |
if(key==='professione') { | |
result[col] = {}; | |
result[col][key]=count; | |
count++; | |
} | |
}*/ | |
} | |
}); | |
if(!isEmpty(result)) | |
print(result); | |
} | |
professioneScan(col); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment