Design Search for Your Data Model
On this page
Atlas Search provides several methods to help you optimize queries for different data models. Use the following tutorials to learn common design patterns so you can effectively query your data with Atlas Search.
Prerequisites
To complete the tutorials, you must have:
An Atlas cluster with MongoDB version 4.2 or higher.
The sample data loaded into your Atlas cluster.
Project Data Access Admin
or higher access to your Atlas project to create Atlas Search indexes.Search Tester,
mongosh
, Compass, or a supported MongoDB Driver to run queries on your cluster.
Note
You can run Atlas Search queries by using any driver
through the $search
aggregation stage.
These tutorials include examples for a selection
of clients. Refer to the specific tutorial page for details.
You can also complete these tutorials with local Atlas deployments that you create with the Atlas CLI. To learn more, see Create a Local Atlas Deployment.
Query Non-String Fields with String-Specific Operators
Certain Atlas Search operators, like queryString and autocomplete, support only string fields. If you need to query non-string fields using these operators, you can convert the values of these fields to strings and store the converted fields in a materialized view. A materialized view lets you use string-specific operators to query the converted fields and keep the original data intact in the source collection.
To get started, see How to Search Non-Alphabetical Data as Strings.
Query Fields Inside Embedded Documents
You can use Atlas Search to query fields inside an array of documents, even when the array of documents is nested. After you index the document fields as the embeddedDocuments type, you can run queries against the fields inside these documents, including fields inside the following types of arrays:
Array of documents.
Array of documents inside a document.
Array of documents inside an array of documents.
To get started, see How to Run Atlas Search Queries Against Fields in Embedded Documents.
Query Across Multiple Collections
When your search must span multiple collections, you can use the following methods to search across them:
To join collections and search across them, use the
$lookup
stage with$search
.To combine search results from multiple collections, use the
$unionWith
stage.To consolidate multiple collections so you can index and search them together, create a materialized view.
To get started, see How to Run Atlas Search Queries Across Multiple Collections.