Define Stored Source Fields in Your Atlas Search Index
On this page
The Atlas Search index storedSource
option and $search
returnStoredSource option are in preview, but can be
used in production applications. If there are any syntax or behavior
changes between the preview stage and general availability (GA), we
will proactively communicate before introducing any breaking changes.
The MongoDB Cloud Support team will help troubleshoot any issues
related to using this feature as part of your contract.
The storedSource
option in an Atlas Search index definition specifies the fields in the source document
that Atlas Search must store. Atlas Search doesn't index stored fields and so you
can't query these fields, but you can retrieve stored fields at query
time using the returnStoredSource option. In certain cases, this configuration improves query
performance by avoiding implicit query time lookup on the backend
database. You can store fields of all BSON Data Types on Atlas Search.
storedSource
is only available on Atlas clusters running one of
the following versions:
- MongoDB 4.4.12+
- MongoDB 5.0.6+
To learn more about retrieving the stored fields, see Return Stored Source Fields.
Syntax
The storedSource
option has the following syntax in an index
definition:
{ ..., "storedSource": true | false | { "include" | "exclude": [ "<field-name>", ... ] } }
Options
The storedSource
option takes a boolean value or an object in the index definition.
Boolean Values
Value | Description |
---|---|
true | Specifies that Atlas Search must store all the fields in the
documents. Storing full documents might significantly impact
performance during indexing and querying. To learn more,
see Storing Source Fields. |
false | Specifies that Atlas Search must not store the original source
document. This is the default value for the storedSource
option. |
Object
The storedSource
option object accepts one of the following
fields:
The object must contain either include
or exclude
.
Field | Type | Description |
---|---|---|
include | array of strings | List that contains the field names or dot-separated paths to
fields to store. In addition to the specified fields, Atlas Search
stores _id also by default. |
exclude | array of strings | List that contains the field names or dot-separated paths to
fields to exclude from being stored. If specified, Atlas Search stores
original documents except the fields listed here. |
Examples
The following index examples use the fields in the
sample_mflix.movies
collection to demonstrate how to configure the
fields to store on Atlas Search using the storedSource
option. The
examples use the dot notation
to specify embedded fields.