How to index a MongoDB field that holds an array of strings?

Viewed 18

In my collection, documents will contain a field that holds an array like so:

{
  field_a: ["banna", "orange", "kiwi"]
}

How to index this collection based on this field?

The queries will be something like:

Find all documents where field_a is a subset of a given array.

1 Answers

You can create an index like this:

db.col.createIndex({ 'field_a': 1 })
Related