Working with Text Indexes
1. Creating Text Index
| Form | Effect |
|---|---|
createIndex({title: "text"}) | Single-field text index |
| Limit | One text index per collection |
2. Creating Compound Text Index
| Form | Effect |
|---|---|
createIndex({title:"text", body:"text"}) | Multi-field text |
| Wildcard | {"$**":"text"} indexes all string fields |
3. Setting Text Index Weights
| Aspect | Detail |
|---|---|
| Option | { weights: { title: 10, body: 1 } } |
| Effect | Multiplies term score per field |
| Default weight | 1 |
4. Setting Default Language
| Option | Effect |
|---|---|
| default_language | Stemming/stop-word language (e.g., "english", "spanish") |
| "none" | Disables stemming and stop words |
5. Using Language Override
| Option | Effect |
|---|---|
| language_override | Field name holding per-doc language (default "language") |
| Use | Multi-lingual content in one collection |
6. Creating Wildcard Text Index
| Form | Effect |
|---|---|
createIndex({"$**": "text"}) | Indexes all string fields |
| Cost | Larger index; slower writes |
7. Dropping Text Index
| Form | Note |
|---|---|
dropIndex("title_text") | Default name pattern |
| getIndexes() | Confirm exact name |
8. Understanding Text Index Limitations
| Limitation | Detail |
|---|---|
| One per collection | Cannot have two text indexes |
| No phrase fuzziness | Use Atlas Search for fuzzy |
| No prefix wildcard | Use Atlas Search autocomplete |
| Cannot hint | $text queries always use text index |