Why does direction of index matter in MongoDB?

前端 未结 3 2000
情话喂你
情话喂你 2020-11-29 16:55

To quote the docs:

When creating an index, the number associated with a key specifies the direction of the index, so it should always be 1 (ascendin

3条回答
  •  生来不讨喜
    2020-11-29 17:22

    The simple answer that you are looking for is that the direction only matters when you are sorting on two or more fields.

    If you are sorting on {a : 1, b : -1}:

    Index {a : 1, b : 1} will be slower than index {a : 1, b : -1}

提交回复
热议问题