Index Management
Create a simple ascending index on a field:
The index list displays all existing indexes on your collection in a table format with the following columns:
VisualLeaf supports all MongoDB index types with specific use cases and configuration options:
| Direction | 1 (Ascending) or -1 (Descending) |
| Use Cases | General-purpose indexes for sorting, filtering, and range queries |
| Best For | Equality matches, range queries, sorting operations |
| Example | Field: email, Direction: 1 for ascending email order |
Create indexes with multiple fields for queries that filter or sort on multiple criteria.
Example: Index on { status: 1, priority: -1, createdAt: -1 } for queries filtering by status and sorting by priority and date.
| Direction | text |
| Use Cases | Full-text search with stemming and stop words |
| Wildcard Option | Use $** as field name to index all string fields |
| Configuration | Set default language, language override field, field weights, and version in Text tab |
| Limitation | Only one text index allowed per collection |
| Direction | hashed |
| Use Cases | Equality queries, sharding keys for even data distribution |
| Best For | Fields with high cardinality that are only queried for exact matches |
| Limitation | Cannot support range queries or sorting |
| Direction | 2d |
| Use Cases | Flat 2D coordinate systems (game maps, floor plans) |
| Data Format | Arrays like [x, y] or objects like {x: 10, y: 20} |
| Configuration | Set min/max coordinate bounds and geohash bits precision in Geospatial tab |
| Direction | 2dsphere |
| Use Cases | Geographic coordinates on Earth (latitude/longitude) |
| Data Format | GeoJSON objects (Point, LineString, Polygon, etc.) |
| Queries | $geoNear, $geoWithin, $geoIntersects with spherical geometry |
| Configuration | Set 2dsphere index version in Geospatial tab (default: version 3) |
| Field Pattern | $** for all fields or fieldName.$** for nested fields |
| Use Cases | Flexible schemas, unpredictable query patterns, indexing all/most fields |
| Projection Control | Include or exclude specific fields using Wildcard Projection in Advanced tab |
| Quick Action | Use "Quick Actions" dropdown to quickly add $** : 1 |
Automatically delete documents after a specified time period. TTL indexes are regular single-field indexes with an expiration setting.
The index creation form is organized into five tabs: General, Collation, Text, Geospatial, and Advanced.
The General tab contains the core index configuration including fields, basic options, and TTL settings.
Define which fields to include in the index and their index types:
Select the index type for each field:
| Direction | Description |
|---|---|
Asc (1) |
Ascending order - standard B-tree index for sorting and range queries |
Desc (-1) |
Descending order - optimized for reverse sorting |
Text |
Full-text search with stemming and stop words |
Hashed |
Hash-based index for equality queries and sharding |
2D |
Flat geospatial coordinates (game maps, floor plans) |
2D Sphere |
Spherical geospatial for Earth coordinates (lat/lng) |
Dropdown menu with common index patterns:
| Action | Index Pattern | Description |
|---|---|---|
| Wildcard Text | $** : text |
Indexes all string fields for full-text search |
| Wildcard Index | $** : 1 |
Indexes all fields in the document |
| _id Field | _id : 1 |
Standard _id index |
| createdAt Field | createdAt : -1 |
Timestamp index, newest first |
| Field | Description | Default |
|---|---|---|
Index Name |
Custom name for the index. If empty, MongoDB auto-generates a name based on fields and directions (e.g., "email_1_status_-1") | Auto-generated |
Unique |
Prevents duplicate values in the indexed field(s). For compound indexes, the combination must be unique. Cannot create if duplicates exist. Allows one null value unless sparse is also enabled. | false |
Sparse |
Only indexes documents that have the indexed field(s). Excludes documents where field is missing or null, resulting in smaller index size. Queries with null checks may not use this index. | false |
Background |
Builds the index in the background, allowing read/write operations to continue (slower build). Foreground builds are faster but block operations. Less critical in MongoDB 4.2+ with optimized index builds. | false |
Hidden |
Makes the index invisible to the query planner. Index is still maintained on writes but not used for queries. Useful for testing index drop impact. Requires MongoDB 4.4+. | false |
Expire After Seconds |
TTL setting. Documents are deleted when (current_time - field_value) exceeds this value. Must be used with a single Date field. Deletion runs every ~60 seconds. Examples: 3600 (1 hour), 86400 (1 day), 2592000 (30 days). | None |
Configure language-specific string comparison and sorting rules. Collation determines how text is compared and sorted based on locale, case sensitivity, accent handling, and more.
Note: To use an index for string comparisons, queries must specify the same collation as the index.
| Field | Description | Options/Default |
|---|---|---|
Locale |
REQUIRED. ICU locale code for language-specific rules. Affects sort order, case, and accent handling. Examples: "en_US", "fr", "de@collation=phonebook", "zh@collation=unihan". | Dropdown with 60+ locales including simple, en, fr, de, es, zh, ja, ar |
Strength |
Comparison strictness level. 1=Primary (base chars only, a=A=a), 2=Secondary (base+accents, a=A but a does not equal a), 3=Tertiary (base+accents+case), 4=Quaternary (punctuation), 5=Identical (all differences). | 1-5, default locale-specific |
Case Level |
Adds case sensitivity with strength 1 or 2. When enabled with strength 1, distinguishes case without distinguishing accents (a does not equal A but a=a). | Checkbox, default false |
Case First |
Controls whether uppercase or lowercase letters sort first. "off" uses locale default, "upper" puts uppercase first (A,a,B,b), "lower" puts lowercase first (a,A,b,B). | off / upper / lower, default off |
Numeric Ordering |
Compares numeric strings by value instead of lexicographically. When enabled: "1","2","3","10","20" instead of "1","10","2","20","3". Useful for version numbers, part numbers. | Checkbox, default false |
Alternate |
Controls handling of spaces and punctuation. "non-ignorable" includes them in comparisons, "shifted" ignores them at lower strength levels (makes "black bird" = "blackbird"). | non-ignorable / shifted, default non-ignorable |
Max Variable |
When alternate="shifted", determines which chars are ignored. "punct" ignores punctuation, "space" ignores both spaces and punctuation. Only applies when alternate is "shifted". | punct / space, default punct |
Backwards |
Compares strings from end to beginning. Primarily for French dictionary sorting where accent position matters more from the end. | Checkbox, default false |
Configure text index options including language processing, stemming, field weights, and version.
| Field | Description | Options/Default |
|---|---|---|
Default Language |
Language for stop words and stemming rules. "english" uses English stop words ("the", "a", "is") and stems words (running → run). "none" disables language processing for exact matching or mixed-language content. | Dropdown with languages: none, danish, dutch, english, finnish, french, german, hungarian, italian, norwegian, portuguese, romanian, russian, spanish, swedish, turkish. Default: english |
Language Override |
Field name containing per-document language (e.g., "lang", "language"). Allows each document to specify its own language for stemming/stop words. Example: {"title": "Bonjour", "lang": "french"} processes with French rules. | Text input Default: empty |
Text Index Version |
Text index algorithm version. Version 3 (recommended) supports Unicode 8.0 case folding and better diacritic handling (cafe matches CAFE). Version 2 for legacy compatibility. | Number input (1-3) Default: 3 |
Field Weights |
Control field importance in search scores. Higher weight = more impact on ranking. Click "Add Field Weight" to add entries. Each entry has field name and weight (1-99,999). Example: title:10, description:5, tags:2 prioritizes title matches. | Field/weight pairs Default: all fields weight 1 |
Configure geospatial index options for 2D and 2D Sphere indexes.
| Field | Description | Default/Range |
|---|---|---|
Min Value |
Minimum coordinate value for 2D indexes. Used for custom coordinate systems (game maps, floor plans). Must be less than Max Value. Only applies to 2d indexes, not 2dsphere. | -180 (geographic longitude) |
Max Value |
Maximum coordinate value for 2D indexes. Used for custom coordinate systems. Must be greater than Min Value. Only applies to 2d indexes, not 2dsphere. | 180 (geographic longitude) |
Bits (Geohash Precision) |
Geohash precision for 2D indexes. Higher = more precision but larger index. 26 bits is approximately 60cm precision, 32 bits is approximately 2cm (max), 20 bits is approximately 40m. | 26, range 1-32 |
Bucket Size |
For geoHaystack indexes (deprecated in 4.4+), defines bucket granularity in coordinate units. Smaller = more precision/larger index. Example: 1 is approximately 111km, 0.1 is approximately 11km, 0.01 is approximately 1.1km. | No default, geoHaystack deprecated |
2dsphere Index Version |
2dsphere index algorithm version. Version 3 (default) supports all GeoJSON types with better performance. Version 2 for legacy compatibility. | 3 (recommended) |
Configure advanced index options including partial filters, wildcard projections, storage engine settings, and cluster options.
| Field | Description | Format |
|---|---|---|
Partial Filter Expression |
Indexes only documents matching this filter. Reduces index size and improves performance for targeted queries. Queries must include the filter to use this index. Supported operators: $eq, $gt, $gte, $lt, $lte, $type, $exists, $and, $or. Examples: {"status": "active"}, {"price": {"$gt": 100}}, {"email": {"$exists": true}}. | JSON object, validated on input |
Wildcard Projection |
For wildcard indexes ($** pattern), specifies which fields to include/exclude. Include: {"field1": 1, "field2": 1}. Exclude: {"excludedField": 0}. Use to index all fields except large/sensitive ones or only specific nested paths. | JSON object, validated on input |
Storage Engine |
Storage engine-specific options. For WiredTiger: {"wiredTiger": {"configString": "block_compressor=zstd"}}. Compression options: none, snappy, zlib, zstd. Advanced option - incorrect settings may harm performance. | JSON object, validated on input |
Commit Quorum |
For replica sets, number of data-bearing nodes that must complete index build. Options: "majority", "votingMembers", or number (1-n). Higher = more durable/slower, lower = faster/less redundancy. Only applies to replica sets. | Number input, default "votingMembers" |
Clustered |
Stores documents in index order on disk. Must be on _id field. Collection must be created with clustered option (cannot add to existing collections). Benefits: fast range queries on _id, reduced _id index storage. Use case: time-series data with timestamp _id. | Checkbox, default false |
Click the "JSON Preview" button at the bottom of the form to see the complete index configuration as a MongoDB createIndex command. Useful for:
Warning: Editing an index drops the existing index and creates a new one. This may take time and affect query performance during the rebuild.
Note: The _id_ index cannot be edited as it is a system index.
Note: The _id_ index cannot be deleted as it is required by MongoDB.
Click the "Refresh" button in the top-right corner to reload the index list from the database. Useful after creating/editing/deleting indexes or when working with indexes modified outside VisualLeaf.
You can access the Index Manager from multiple locations in VisualLeaf:
When viewing collection statistics, you can click on individual indexes to view their details or click "Manage Indexes" to open the Index Manager.
When viewing slow query recommendations in the profiling dashboard, you can click "Create Recommended Index" to open the Index Manager with the recommended index pre-filled.
Every field in the index creation form has a help icon (?) button. Click it to view detailed documentation about that specific field, including:
This context-sensitive help system makes it easy to learn about MongoDB index options without leaving the interface.
| Use Case | Goal | Configuration |
|---|---|---|
| Unique Email Index | Prevent duplicate user email addresses | Field: email, Direction: Asc (1), check Unique. Optionally check Sparse if email is optional. |
| Recent Items First | Efficiently query and sort by creation date, newest first | Field: createdAt, Direction: Desc (-1). For compound: {status: 1, createdAt: -1} to filter by status and sort by date. |
| Full-Text Search | Search product titles and descriptions with stemming | Field: $**, Direction: Text. In Text tab, set Field Weights: {title: 10, description: 5} to prioritize title matches. |
| Session Auto-Expiration | Automatically delete sessions after 24 hours | Field: createdAt (must be Date), Direction: Asc (1), set Expire After Seconds to 86400. |
| Active Users Only | Index only active users to reduce index size | Field: lastLoginAt, Direction: Desc (-1). In Advanced tab, set Partial Filter: {"status": "active"}. |
| Geospatial Search | Find restaurants near a location (lat/lng) | Field: location (GeoJSON Point), Direction: 2D Sphere. Query with $near or $geoWithin. |
| Case-Insensitive Username | Enforce unique usernames regardless of case | Field: username, Direction: Asc (1), check Unique. In Collation tab: Locale en, Strength 1. |
| Wildcard Index | Index all fields in documents with unpredictable structure | Use Quick Actions > "Wildcard Index" to add $** : 1. Optionally add Wildcard Projection to exclude large fields. |
| Error | Cause | Solution |
|---|---|---|
| Duplicate key error | Trying to create unique index on field with duplicate values | Remove duplicates first, or don't use unique option |
| Index name already exists | An index with that name already exists | Choose a different name or leave blank for auto-generation |
| Collation locale required | Collation enabled but no locale selected | Select a locale in Collation tab or disable collation |
| Invalid JSON | JSON syntax error in partial filter, wildcard projection, or storage engine | Check JSON syntax - form shows validation errors |
| Min greater than max | Geospatial min value exceeds max value | Swap values or correct the range |
| Text index already exists | Collection already has a text index (only one allowed) | Drop existing text index first or modify it instead |
Download and start managing your MongoDB databases with ease.
Download Free Trial