I have a Mongo database that I did not create or architect, is there a good way to introspect the db or print out what the structure is to start to get a handle on what types of data are being stored, how the data types are nested, etc?
We can get the schema object/first document of the collection using : var schemaObj = db. users. findOne();
MongoDB is a document-oriented NoSQL database management system (DBMS). Unlike traditional relational DBMSs, which store data in tables consisting of rows and columns, MongoDB stores data in JSON-like structures referred to as documents.
Deducing a Virtual SchemaDbSchema can connect to MongoDB, look in the sample collection records, and deduce a virtual diagram from there. All you have to do is to connect to MongoDB and the tool will deduce the schema automatically. Once the diagram is deduced, the possibilities are endless.
Just query the database by running the following commands in the mongo shell:
use mydb //this switches to the database you want to query show collections //this command will list all collections in the database db.collectionName.find().pretty() //this will show all documents in the database in a readable format; do the same for each collection in the database
You should then be able to examine the document structure.
There is actually a tool to help you out here called Variety:
http://blog.mongodb.org/post/21923016898/meet-variety-a-schema-analyzer-for-mongodb
You can view the Github repo for it here: https://github.com/variety/variety
I should probably warn you that:
As such I recommend you run this on a development server or a hidden node of a replica or something.
Depending on the size and depth of your documents it may take a very long time to understand the rough structure of your database through this but it will eventually give one.
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