how to view keys in collections in mongodb code example
Example 1: mongodb get keys of document
var allKeys = {}; db.YOURCOLLECTION.find().forEach(function(doc){Object.keys(doc).forEach(function(key){allKeys[key]=1})}); allKeys;
Example 2: mongodb list all keys
var getKeys = function(collName) { var keys = {}; db.getCollection(collName).find().forEach(function(value) { Object.keys(value).forEach(function (keyName) { if(keys[keyName]) { keys[keyName] += 1; return; } keys[keyName] = 1; }); }); return keys; }
getKeys('zips')