Export Your Schema
On this page
You can export your schema after analyzing it. This is useful for sharing your schema and comparing schemas across collections.
Before you Begin
If you have not already done so, analyze your schema:
Analyze the schema.
Click Analyze Schema.
When Compass analyzes your schema, it samples a random subset of documents from your collection. To learn more about sampling, see Sampling.
Once your schema has been analyzed, use the following procedure to export your schema.
Steps
Standard Format Schema Object Properties
Standard format schema objects contain the following fields:
Property | Data type | Description |
---|---|---|
| string or array | JSON type of this data type. For details, see the official JSON docs. |
| array of strings | Fields that must appear in the schema. For details, see the official JSON docs. |
| object | Properties for each field. Keys are property names and values are subschemas. For details, see the official JSON docs. |
| document | Metadata about elements in array fields. Metadata appears as embedded subschemas. For details, see the official JSON docs. |
This is not an exhaustive list of all possible fields. For details on additional fields, see the official JSON Schema spec.
MongoDB Format Schema Object Properties
MongoDB format schema objects contain the following fields:
Property | Data type | Description |
---|---|---|
| string or array of strings | BSON type of this field. |
| array of strings | Fields that must appear in the schema. |
| document | Properties for each field. Keys are property names and values are subschemas. |
| document | Metadata about elements in array fields. Metadata appears as embedded subschemas. |
This is not an exhaustive list of all possible fields. For details on additional fields, see the official JSON Schema spec.
Expanded Format Schema Object Properties
Expanded format schema objects contain these fields in addition to the Standard Schema fields:
Property | Data type | Description |
---|---|---|
| string or array | BSON type of this field. |
| document | Document containing metadata about the field. |
| boolean |
|
| float | Probability that the field exists in a random document. |
| integer | Number of documents from the sample that have this field. |
| array | Sample values as Expanded JSON. Sample values are limited to the first 100 characters. |
This is not an exhaustive list of all possible fields. For details on additional fields, see the official JSON Schema spec.
Limitations
Compass cannot export a schema that has more than 1000 distinct fields. If you try to export a schema with more than 1000 distinct fields, Compass returns an error.
Example Schema
The following example uses a collection of 3 documents, each
with a title
field and unique information about that movie:
1 [ 2 { 3 "_id": { "$oid": "573a1390f29313caabcd6223" }, 4 "title": "The Poor Little Rich Girl", 5 "plot": "Gwen's family is rich, but her parents ignore her and most of the serv...", 6 "year": 1917, 7 }, 8 { 9 "_id": { "$oid": "573a1391f29313caabcd7616" }, 10 "title": "Salomè", 11 "plot": "Salome, the daughter of Herodias, seduces her step-father/uncle Herod, ...", 12 "year": 1922, 13 "genres": [ "drama", "horror" ] 14 }, 15 { 16 "_id": { "$oid": "573a1392f29313caabcd9c1b" }, 17 "title": "Payment Deferred", 18 "year": 1932, 19 }, 20 ]
You can import the above example to MongoDB Compass to experiment with schema outputs. To import the example collection into MongoDB Compass:
Copy the JSON documents to your clipboard.
Copy the above JSON documents.
The example above outputs the following schema: