MongoDB Multikey Indexes (original) (raw)

Last Updated : 5 May, 2026

MongoDB Multikey Indexes automatically index array fields to speed up queries on individual elements within arrays, improving performance for datasets with nested or list-based values.

Create a Multikey Index

When an index is created on an array field, MongoDB generates separate index entries for each array element, enabling efficient equality and membership queries as well as index-supported sorting on array values.

**Syntax:

db.Collection_name.createIndex({field_name: 1/ -1})

Examples of MongoDB Multikey Indexes

In the following example, we are working with:

Screenshot-2026-02-19-122502

Example 1: Index Basic Arrays

Create multi-index with the help of createIndex() method on the field language:

db.student.createIndex({language:1})

**Output:

Screenshot-2026-02-19-122608

Check the index using the getIndexes() method:

Screenshot-2026-02-19-122831

Example 2: Index Arrays with Embedded Documents

Create a multikey index on an array field that contains nested documents/objects.

db.student.createIndex({"details.age":1, "details.branch":1})

**Output:

Screenshot-2026-02-19-123035

Check the index using the getIndexes() method:

Screenshot-2026-02-19-123118

Limitations of MongoDB Multikey Indexes

While MongoDB multikey indexes offer significant performance improvements, they come with some limitations and constraints:

Important Points of MongoDB Multikey Indexes

Here are some important point discussed: