Analyze Your Data Schema
The Schema tab provides an overview of the data type and shape of the fields in a particular collection. Databases and collections are visible in the left-side navigation.
The overview is based on sampling the documents in the collection. The schema overview may include additional data about the contents of the fields, such as the minimum and maximum values of dates and integers, the frequency of occurrence of particular values, and the cardinality of the data.
MongoDB has a flexible schema model, which means that some fields may
contain different types of data from one document to the next. For
example, a field named address
may contain strings and integers in
some documents, objects in others, or some combination of all three.
In the case of heterogenous fields, the Schema tab shows a breakdown of the various data types contained within the field with the percentage of each data type represented.
Example
The Schema tab shows size information about the
test.restaurants
collection at the top, including the total
number of documents in the collection, the average document size,
and the total disk space occupied by the collection.
The following fields are shown with details:
The
_id
field is an ObjectId. Each ObjectId contains a timestamp, so Compass displays the range of creation times for the sampled documents.The
address
field contains four nested fields. You can expand the field panel to see analyses of each of the nested fields.The
borough
field contains a string indicating the borough in which the restaurant is located. The cardinality is low enough that Compass can provide a graded bar of the field contents, with the most-frequently occurring string on the left.The
categories
field contains arrays of strings. The analysis shows the minimum, maximum, and average array lengths.
![Example of a collection's schema](/docs/compass/current/static/4cd1e45c4cbec16c31f6a3439ce0b0d9/23278/collection-schema.webp)
Query Bar
Using the query bar in the Schema tab, you can create a query filter to limit your result set. Click the Options button to specify query options, such as the particular fields to display and the number of results to return.
Note
For query result sets larger than 1000 documents, Compass shows a subset of the results. Otherwise, Compass shows the entire result set.
For details on sampling, see Sampling.
![Query bar schema view](/docs/compass/current/static/0dd394f2d6f35feb45c30917ef5c6dd1/622cb/query-bar-schema-view.webp)
Tip
In the Schema tab, you can also use the Query Builder to enter a query into the query bar.
Field Descriptions
For each field, Compass displays summary information about the data type or types the field contains and the range of values. Depending on the data type and the level of cardinality, Compass displays histograms, graded bars, geographical maps, and sample data to provide a sense of the shape and scope of the data contained in each field.
Field with a Single Data Type
Below is an example of the data type summary for a field called
last_login
which contains data of type date
.
![Example of a field with a single data type](/docs/compass/current/static/476883c66c3d6fd61c7dfa2fbfc28c9a/ea1c2/field-example.webp)
Field with Multiple Data Types
For fields that contain multiple data types,
Compass displays a percentage breakdown of
the various data types across documents. In the example below,
the chart shows the contents of a field called phone_no
in which
81% of documents are of type string
, and the remaining 19% are of
type number
.
![Example of percentage breakdown for data types](/docs/compass/current/static/33a9a81b9925ac4193537848b8e15c4b/ea1c2/field-percentage-breakdown.webp)
Missing Field
If a collection contains documents in which not all fields contain
a value, the missing values display as undefined
. In the example
below, the field age
has no recorded value in 40% of the sampled
documents.
![Example of sparcely applied data type](/docs/compass/current/static/733a36f4c5cd4bc16e88a3f6bb24d70a/ea1c2/field-sparsity.webp)
Strings
Strings can appear in three different ways. If there are entirely unique strings in a field, Compass shows a random selection of string values from the specified field. Click the circular refresh icon to see a new set of randomly selected values from the field.
![Example of string data types](/docs/compass/current/static/e039707f5a1ac4c668b4d3cc59b8e274/12657/string-sample.webp)
If there are only a few different string values, Compass shows the strings in a single graded bar which shows the percentage of the population of the string values.
![Example of few string data types](/docs/compass/current/static/78fb11d985085876401852f1ef271610/ff210/string-sample2.webp)
If there are multiple string values with some duplicates, Compass shows a histogram indicating the frequency of each string found within the field.
![Example of string data types as a histogram](/docs/compass/current/static/498486a83390623caf633f3cbc655ab1/e804a/string-sample3.webp)
Note
Move the mouse over each bar to display a tooltip which shows the value of the string.
Numbers
Numbers are similar to strings in their representation. Unique numbers are shown in the following manner:
![Example of number data type](/docs/compass/current/static/1d3cf85a47555f1979d1b61b8298e2b9/cfa85/number-sample.webp)
Duplicate numbers are shown in a histogram that indicates their frequency:
![Example of duplicate number data types](/docs/compass/current/static/0db42a27c28cc21f0e470dc27e2715a0/b589c/number-sample2.webp)
Dates and ObjectIDs
Fields that represent dates (and fields that contain the ObjectID data type, which includes a timestamp) are shown across multiple bar charts. The two charts on the top row represent the day of the week and time of day of the timestamp value.
The single chart on the bottom shows the first and last timestamp value, and the vertical lines represent the distribution of the timestamp across the range of first to last.
![Example of Date data types](/docs/compass/current/static/71781b6cb6156916ee3707ca13ccb488/514ab/date-sample.webp)
Embedded Documents and Arrays
Fields that contain a sub-document or an array are displayed with a small triangle next to them and a visual representation of the data contained within the sub-document or array.
![Example of fields with embedded documents or arrays](/docs/compass/current/static/b38547301d703760522ca4bba6e8f6b6/4a5f2/embedded-document-sample.webp)
Click on the triangle to expand the field and view the embedded documents:
![Expanding the embedded documents](/docs/compass/current/static/99486a8ca7e7b276adf87617e5a7939e/0d2b6/embedded-document-sample2.webp)
GeoJSON and [longitude,latitude]
Arrays
Fields that contain GeoJSON data or [longitude,latitude]
arrays are
displayed with interactive maps. For more information on interacting
with location data in Compass, see Analyze Location Data.
![Example of GeoJSON data types](/docs/compass/current/static/21d894124c6367406b6bfe16884e3502/4e6c6/geo-visualization.webp)
Note
Third party mapping services are not available in Compass Isolated Edition.
View Charts of Mixed Types
If a field has mixed types, you can view different charts of each type
by clicking on the type
field. In the example below, the age
field shows the values that are strings:
![Example of a field with mixed types](/docs/compass/current/static/8f3025151a190498fe93bb385eca889c/5fac9/mixed-sample.webp)
Clicking on the number
type causes the chart to show its numeric
data:
![Example that shows numeric data for number type](/docs/compass/current/static/16ce0cbcd19f3536e27a622762a76236/97eb0/mixed-sample2.webp)
Query Builder
In the Schema tab, you can type the filter manually into the query bar or generate the filter with the Compass query builder. The query builder allows you to select data elements from one or more fields in your schema and construct a query matching the selected elements.
Tip
You can compose the initial query filter by using the clickable query builder and then manually edit the generated filter to your exact requirements.
The following procedure describes the steps involved in building a complex query with the query bar.
Analyze Location Data
In the Schema tab, you can use interactive maps to filter
and analyze location data. If your field contains
GeoJSON data or
[longitude,latitude]
arrays, the Schema tab displays
a map containing the points from the field. The data type
for location fields is coordinates
.
![Image showing example field with location data](/docs/compass/current/static/b402f7eda7d20402b7102a0d1179d88b/6506f/location-data-example.webp)
Apply a Location Filter
You can apply a filter to the map to only analyze a specific range of points. To define a location filter:
Click the Circle button at the top-right of the map.
Click and drag on the map to draw a circle containing the area of the map you want to analyze.
Repeat this process as desired to include additional areas of the map in the schema analysis.
![Image showing map with filter circles drawn](/docs/compass/current/static/036f1cf13249959753135b942555287f/6ec0a/location-data-filter.webp)
The query bar updates as you draw location filters to show the exact coordinates used in the $geoWithin query applied to the schema analysis.
If you specify multiple location filters, the query becomes
an $or query
with multiple $geoWithin
operators.
Edit a Location Filter
To move or resize a location filter, click on the right side of the map. You will enter the filter editing mode, which looks like this:
![Image showing map filter editing](/docs/compass/current/static/6465cd79863906ae79fee5e203d1e945/b3e00/location-data-filter-edit.webp)
- To move a filter
- Click and drag the square in the center of the circle.
- To resize a filter
- Click and drag the square at the edge of the circle.
After modifying your filters, click Save.
Delete a Location Filter
To delete a location filter from the map:
Click on the right side of the map.
Either click:
A location filter to delete that filter.
Clear All to delete all location filters.
Click Save.
Troubleshooting
If the analysis of your schema times out, it might be because the
collection you are analyzing is very large, causing MongoDB to stop the
operation before the analysis is complete. Increase the value of
MAX TIME MS
to allow the operation time to complete.
To increase the value of MAX TIME MS:
In the query bar, expand Options.
Increase the value of MAX TIME MS to accommodate your collection. MAX TIME MS defaults to 60000 milliseconds, or 60 seconds, but large collections might take tens of seconds to analyze.
Once you have increased the value of MAX TIME MS, retry your schema analysis by clicking Analyze.