Loading lessons...
Atlas Search
Atlas Search
Atlas Search is MongoDB Atlas's built-in full-text search engine, powered by Apache Lucene - the same engine behind Elasticsearch and Solr.
How it differs from normal indexes
Regular indexes are created with db.collection.createIndex(). Atlas Search indexes are built in the Atlas UI (under the Search tab) and then used from an aggregation pipeline.
Create a search index
In the Atlas dashboard:
- Open your cluster's Search tab.
- Click Create Search Index.
- Use the Visual Editor, name it, and choose the database and collection.
- Wait for the index to finish building.
Search inside an aggregation pipeline
Use the $search stage - it must be the first stage:
db.movies.aggregate([
{
$search: {
index: "default",
text: {
query: "star wars",
path: "title"
}
}
},
{ $project: { title: 1, year: 1 } }
])
- If the index is named
default, you can omit theindexfield. text.queryis the search text;text.pathis the field to search.- This finds movies whose title contains "star" or "wars".
Key facts
$searchcan only be the first stage of a pipeline.- It returns relevance-ranked results.
- Built in the Atlas UI, not via
createIndex().
TL;DR
- Atlas Search = full-text search powered by Lucene.
- Search indexes are created in the Atlas UI.
- Use the
$searchstage (first stage only) in an aggregation pipeline.