Skip to content

Schema analysis and options

  • MongoDB

Schema analysis reads a sample of a collection and shows every field it found, the mix of BSON types each field holds and the share of documents that have it. From the result you can export a JSON Schema, export or apply a $jsonSchema validator. The options panel shows a collection’s or view’s settings and changes its validation, expiry and name.

Schema analysis of 86 sampled products: each field with its type and how often it occurs, discontinued_at selected and present in 27% of documents, and a $jsonSchema validator ready to apply.Schema analysis of 86 sampled products: each field with its type and how often it occurs, discontinued_at selected and present in 27% of documents, and a $jsonSchema validator ready to apply.
See every field's types and frequency, then apply the result as a validator.
  1. Choose Analyse schema from a collection’s menu in the explorer, or Tools › Schema in the collection view.
  2. Set the Sample size (1,000 by default, up to 100,000) and, optionally, a Filter (optional) such as { status: 'open' }.
  3. Choose Analyse. Cancel stops a long run.

The summary reads, for example, “1,000 documents sampled · 12 top-level fields”. The fields form a tree; Expand all and Collapse all open or close every level.

Column Shows
Field The field name, nested under its parent.
Types A bar of the BSON types found, such as Int32 100%.
In documents The share of sampled documents that have the field.

Select a field to see its query path, how often it appears, and its Top values (marked “approximate” when they are estimated).

Under Export, Required when in decides which fields the schema marks as required: those in all documents, 99%, 90% or half of them.

Button What it does
Save JSON Schema… Saves the schema as a JSON Schema file.
Save $jsonSchema validator… Saves it as a $jsonSchema validator.
Copy Copies the one beside it to the clipboard.
  1. Under Apply as validator, pick the Validation level (strict, moderate or off) and the Validation action (error, warn or errorAndLog).
  2. Check the collMod command shown below them.
  3. Choose Apply as validator…, then Apply in the confirmation.

From then on, the document editor shows which rules a refused document breaks. A view cannot take a validator, and a read-only connection cannot apply one.

Choose Options from a collection’s or view’s menu, or Tools › Options in the collection view. The panel has these sections:

Section What you can do
Overview See the Type, Documents, Data size and Index size, the time series fields, a view’s source and pipeline, and All options.
Validation Edit the validator (a query document or { $jsonSchema: … }; empty removes it), Validation level and Validation action, then Save validation….
Expiry For time series and clustered collections: Delete documents after (seconds; empty or off for never), then Save expiry….
Rename Enter a New name, optionally Replace an existing collection of that name, then Rename….
Drop Drop collection… or Drop view….

Views have no Validation section. Each section shows the command it runs, and a rename or a drop always asks before it runs.

Documents Querybara 0.1.1 · built frombc9f5aa