sampleSchema() - Return document structure command

Returns the structure of JSON documents in a collection.

Syntax diagram

Read syntax diagramSkip visual syntax diagramdb.collection. sampleSchema(rows )

Command parameters

rows
This optional parameter specifies a number of rows to sample. If you set the parameter to 0 or do not provide a value, the structures of all documents in a collection are returned.

Example

View the structure of a JSON document in the books collection:
db.books.sampleSchema()
Sample output is as follows:
  {
  "._id":"15;type:ObjectId",
  ".abstract":"15;type:String",
  ".author":"15;type:String",
  ".category":"12;type:String",
  ".isbn":"15;type:String",
  ".pages":"14;type:Integer",
  ".price":"14;type:Double",
  ".sales":"13;type:Double",
  ".title":"15;type:String",
  ".year_published":"5;type:Integer"
  }