Multikey indexes for array fields in MongoDB

Multikey indexes in MongoDB

A multikey index is used to index fields that contains an array value. Those multikey indexes can work with scalar values (like an array of string, number, etc) or an array of nested documents.

Create a Multikey Index

To create a multikey index we use an operation that resembles to the following prototype (there is no need to specify the type of the multikey index, MongoDB will handle this part in your place):

db.collection.createIndex( { <field>: < 1 or -1 > } )

For more information, visit the official mongodb documentation: Multikey Indexes