The createSearchIndexes database command creates Atlas Search indexes. In mongosh, db.collection.createSearchIndex() wraps the command, accepting an index name and a configuration document. The index makes collection fields available to full-text queries. section 13.5 section 11.6
To create and use a full-text index:
- Choose a mapping. Dynamic mapping is convenient for a local test; static mapping indexes only predefined fields and can improve search performance, prevent schema conflicts, and keep field handling consistent. section 13.5.1 section 11.4
- In mongosh, select the database and call createSearchIndex() on the collection with an index name and mappings document. section 11.6 section 13.5.1
- Check db.collection.getSearchIndexes() for status READY and queryable: true before using the named index in a $search query. section 13.5.1
use sample_training
db.inspections.createSearchIndex(
"LocalSearchIndex",
{ mappings: { dynamic: true } }
)
This mongosh example creates LocalSearchIndex on sample_training.inspections with dynamic mapping for a local Atlas cluster. section 13.5.1
For hosted Atlas deployments, these mongosh search-index management commands require an M10-or-higher cluster. The Atlas CLI offers a separate creation path using an index-definition file. Once an index exists, related mongosh methods can update or drop it; getSearchIndexes() can inspect its status. section 11.6 section 11.4 section 13.5.1
