In this blog I am going to share the steps for getting information of schema of a collection.
Let say we have a collection named “posts” and we want to get names of fiels in all documents in that collection.
> mr = db.runCommand({ "mapreduce" : "posts", "map" : function() { for (var key in this) { emit(key, null); } },"reduce" : function(key, stuff) { return null; } , "out": "posts" + "_keys"}); { "result" : "posts_keys", "timeMillis" : 441, "counts" : { "input" : 1000, "emit" : 8000, "reduce" : 80, "output" : 8 }, "ok" : 1 } > db[mr.result].distinct("_id") [ "_id", "author", "body", "comments", "date", "permalink", "tags", "title" ] >
The output of second command gives names of all fields in “posts” collection.
Akash Sharma
More From Oodles
Ready to innovate? Let's get in touch
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Akash Sharma
Akash is a bright Groovy and Grails developer and have worked on development of various SaaS applications using Grails technologies. Akash loves playing Cricket and Tennis