Scope: MongoDB indexes are general-purpose indexes used for a wide range of query optimizations. In contrast, MongoDB Atlas Search indexes are specialized for full-text search and related functionalities.
Index in MongoDB : used for efficient execution for the query by limiting the number of documents getting scanned for the inspect.
Atlas Search : Leverages the power of Apache Lucene to enable full text search indexes for your data.
articles in your MongoDB database with documents that look like this:{
"title": "Learning MongoDB",
"content": "MongoDB is a NoSQL database that offers high performance...",
"tags": ["database", "NoSQL", "MongoDB"]
}
Collections button.articles) for which you want to create the search index.Indexes tab and then the Create Search Index button.Dynamic Mapping to automatically index all text fields or define a Custom Mapping if you need more control.db.articles.aggregate([
{
$search: {
"text": {
"query": "high performance",
"path": "content" // Search in the 'content' field
}
}
},
{
$limit: 10 // Limit to the first 10 results
}
])
{
$search: {
"compound": {
"must": [
{
"text": {
"query": "MongoDB",
"path": "title"
}
}
],
"should": [
{
"text": {
"query": "NoSQL",
"path": "tags"
}
}
]
}
}
}
STORAGE SIZE: 9.79GB LOGICAL DATA SIZE: 36.59GB TOTAL DOCUMENTS: 51027194 INDEXES TOTAL SIZE: 2.66GB