4

This is a record in mongodb.

{
  numbers: [1,2,3,4,5]
}

As title, If I create an indexing in mongo like

{
  numbers: 1
}

It will works? Or index works only on single value like number or string type?

1 Answer 1

4

Yes, you can and it works:

To index a field that holds an array value, MongoDB creates an index key for each element in the array. These multikey indexes support efficient queries against array fields. Multikey indexes can be constructed over arrays that hold both scalar values 1 (e.g. strings, numbers) and nested documents.

please visit the doc: Mongodb documentation

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. The example is nested array so I miss it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.