Find all columns of a collection in MongoDB

Visakh Vijayan - May 9 '21 - - Dev Community

Since collections are not structured i.e. all documents don't follow the same structure, it becomes hard to find out the exhaustive list of keys in a document.

Even though there are answers on Stackoverflow where they have solved it using MapReduce in MongoDB, the easiest way I found was to use the "Analyze Schema" option of MongoDB Compass. It gives an overview of all the keys and data variations in a nice UI.

Alt Text

Comment below if you have an easier way to do this.

Happy programming!

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .