Docs Menu
Docs Home
/
MongoDB Atlas
/ / / /

How to Index Fields in Objects and Documents

On this page

  • Review document Type Limitations
  • Define the Index for the document Type
  • Configure document Field Properties
  • Try an Example for the document Type

You can use the Atlas Search document type to index fields in objects or documents.

If you enable dynamic mappings, Atlas Search automatically indexes fields of type document. You can use the Visual Editor or the JSON Editor in the Atlas UI to index fields as the document type.

You can't use the Atlas Search document type to index fields in objects or documents that are inside an array. Instead, use the Atlas Search embeddedDocuments type to index fields in objects or documents that are elements of an array.

To define the index for the document type, choose your preferred configuration method in the Atlas UI and then select the database and collection.

The Atlas Search document type takes the following parameters:

Option
Type
Necessity
Description
Default
type
string
Required
Human-readable label that identifies the field type. Value must be document.
dynamic
boolean
Optional

Flag that indicates whether Atlas Search recursively indexes all fields and embedded documents. If set to true, Atlas Search recursively indexes all fields and embedded documents in the document except fields of certain data types.

To index all fields in a document including fields that Atlas Search doesn't dynamically index, define the fields in the index definition.

If omitted or set to false, you must specify individual fields to index.

Important

Atlas Search dynamically indexes all fields in a document using the default settings for the detected data type. Atlas Search also dynamically indexes all nested documents under the document, unless you explicitly override by setting dynamic to false.

false
fields
document
Optional
Document that maps field names to field definitions. To learn more, see an example. This is required if dynamic is omitted or set to false.

The following index definition example uses the sample_mflix.movies collection. If you have the sample data already loaded on your cluster, you can use the Visual Editor or JSON Editor in the Atlas UI to configure the index. After you select your preferred configuration method, select the database and collection, and refine your index to add field mappings.

The index definition indexes the awards field as the document type. It also configures Atlas Search to automatically index all the dynamically indexable fields inside the awards object.

Tip

See also: Additional Index Definition Examples

← dateFacet