I'm coding a mongoose schema so I need a list of possible field in my collection. Please how can I display all fields names in a specific collection, thank you.
switch to the db you're using and type:
mr = db.runCommand({
"mapreduce" : "myCollectionName",
"map" : function() {
for (var key in this) { emit(key, null); }
},
"reduce" : function(key, stuff) { return null; },
"out": "myCollectionName" + "_keys"
})
once you get result, type:
db[mr.result].distinct("_id")
and you will get a list of fields names.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With