Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

A script for mongo shell to get the collection structure.

View mongo-struc.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
var conn = new Mongo();
db = conn.getDB(<DB_NAME>);
var cursor = db.<COLLECTION>.find();
var items = [];
items = cursor.toArray();
var dbstruc = {};
for (var i = 0; i < items.length; ++i) {
var target = items[i];
getKP(target,dbstruc);
}
printjson(dbstruc);
 
function getKP (target,dbstruc) {
for (var k in target) {
if(typeof target[k] !== "object"){
if (target.hasOwnProperty(k) && !dbstruc.hasOwnProperty(k)) {
dbstruc[k] = typeof target[k];
}
}else{
dbstruc[k] = {};
getKP(target[k],dbstruc[k]);
}
}
}
abt3bs commented

works like a charm! Howver, I subsequently found the robomongo app and it's a nice tool to use in conjuction with mongo!

abt3bs commented

works like a charm! However, I subsequently found the robomongo app and it's a nice tool to use in conjuction with mongo!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.