How to infer schema for a Mongodb database?

I want to inspect a Mongodb database collection and detect its schema. What are some recommended approaches? For example, I see that Airbyte data integration software does this by inspecting a fixed number of records in the collection and coming up with a schema based on these records - Mongo DB | Airbyte Documentation

Are there any better ways of doing this?

i can’t think of any.

Mongodb is schemaless db, so no such metadata. The only way would be trying to find a pattern from the data rows directly.

Hey @Pramod_Biligiri,

Thank you for reaching out to the MongoDB Community forums.

When you say “detect its schema” do you mean Analyze Your Data Schema. If so, you can accomplish this using MongoDB Compass. In MongoDB Compass, the Schema tab provides a breakdown of the various data types present in the fields, along with the percentage representation of each data type.

In the Schema tab, you can also use the query bar to create a filter and limit your results. You can click on Options to specify the fields to display and the number of results to return.

Please let me know if the above response addresses your question or if you have any further inquiries or concerns.


Thanks for the responses. I am trying to do this through a program so I can’t use the Compass UI for this. But it does looks like the approach is to inspect the data and then decide, so I guess I’m on the right track.