Navigation

Schema

Not Available in Compass Community Edition

Schema Tab Overview

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.

In the example below, 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.
../_images/collection-schema.png

Query Bar

Note

For query result sets larger than 1000 documents, Compass shows a sampling of the results. Otherwise, Compass shows the entire result set.

For details on sampling, see the FAQ.

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.

../_images/query-bar-schema-view.png

You can type MongoDB queries into the query bar. In the query expression, you can use any MongoDB query operator except $text.

As you type, the Analyze button is disabled and the Filter label turns red until a valid query is entered. Filter syntax requires strict extended JSON types. For details on using the query bar, see Query Bar Options.

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.

../_images/field-example.png

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.

../_images/field-percentage-breakdown.png

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.

../_images/field-sparsity.png

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.

../_images/string-sample.png

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.

../_images/string-sample2.png

If there are multiple string values with some duplicates, Compass shows a histogram indicating the frequency of each string found within the field.

../_images/string-sample3.png

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:

../_images/number-sample.png

Duplicate numbers are shown in a histogram that indicates their frequency:

../_images/number-sample2.png

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.

../_images/date-sample.png

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.

../_images/embedded-document-sample.png

Click on the triangle to expand the field and view the embedded documents:

../_images/embedded-document-sample2.png

GeoJSON and [latitude,longitude] Arrays

Fields that contain GeoJSON data or [latitude,longitude] arrays are displayed with interactive maps.

../_images/geo-visualization.png

Note

Third party mapping services such as Mapbox 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:

../_images/mixed-sample.png

Clicking on the number type causes the chart to show its numeric data:

../_images/mixed-sample2.png

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.

Composing $OR filter conditions is not yet possible with the clickable query builder, but you can manually enter them in the query bar.

The following procedure describes the steps involved in building a complex query with the query bar.

1

Click the chart value.

In the Schema view, you can click on a chart value to build a query. For example, the following image shows the query filter built by clicking the EWR value for the departureAirportFsCode field.

../_images/query-builder.png
2

Optional. Select multiple values.

To select multiple values for a field, click and drag the cursor over a selection of values, or press shift+click on the desired values.

../_images/query-builder3.png
3

Optional. Click on other field values to create a compound query.

For example, the following image shows shows the compound query built by selecting a value in the flightId field.

../_images/query-builder2.png
4

Optional. Deselect a value.

To deselect a previously selected value, shift+click on the selected value:

../_images/query-builder4.png
5

Run the query

To run the query, click Analyze. Click Reset to clear your query.

Note

You can also use the query builder on data represented as maps.

←   Documents Explain Plans  →