Docs Menu
Docs Home
MongoDB Atlas
/ / / /

How to Index Date Fields

On this page

  • Define the Index for the date Type
  • Configure date Field Properties
  • Try an Example for the date Type

You can use the Atlas Search date type to index date values. You can query fields of type date using the Atlas Search range, near, and equals operators. To run a facet query on date fields, you must index the date fields using dateFacet.

You can also use the date type to index:


To query indexed date values inside arrays, you must use the range operator. You can't use the near operator to query date values stored in an array, even if you have an Atlas Search index on the date values inside the array.

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

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

The Atlas Search date type takes the following parameter:

Human-readable label that identifies this field type. Value must be date.

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.


See also: Additional Index Definition Examples

← How to Index Boolean Values