Hi Senthil,
As Scott noted, a more typical source of schema for documentation would be your application code. That said, it may still be useful to infer the schema of an existing collection.
Since MongoDB has dynamic schema, there are several caveats to discovering the overall structure of a collection:
- there is no server-side "schema" to enforce or query for a collection so you have to inspect the documents
- fields present can vary per document within a collection
- fields of the same name can have different types within a collection
- you potentially have to inspect all documents in a collection to infer the overall schema
There are not (as at MongoDB 2.6) any commands or tools included to infer a schema, however there are definitely third party tools for this.
A handy one I'm aware of is Schema.js, which is an add-in for the `mongo` shell that infers the schema in JavaScript via Map/Reduce:
http://skratchdot.com/projects/mongodb-schema/. By default it looks at 50 documents, and you can adjust the limit to more (or all) documents. The output can be inline or to a collection.
Regards,
Stephen