Compound indexes support in MongoDB

Compound indexes support queries on any prefix of the index fields. Index prefixes are the beginning subset of indexed fields. For example, given the index { a: 1, b: 1, c: 1 }, both { a: 1 } and { a: 1, b: 1 }are prefixes of the index.

 

Given the following index:

{ "item": 1, "location": 1, "stock": 1 }

MongoDB can use this index to support queries that include:

  • the item field,
  • the item field and the location field,
  • the item field and the location field and the stock field, or
  • only the item and stock fields; however, this index would be less efficient than an index on onlyitem and stock.

MongoDB cannot use this index to support queries that include:

  • only the location field,
  • only the stock field, or
  • only the location and stock fields.

你可能感兴趣的:(mongodb)