DevilKing's blog

冷灯看剑,剑上几分功名?炉香无需计苍生,纵一穿烟逝,万丈云埋,孤阳还照古陵

0%

Mongodb query performance over ranges

原文链接

针对$in操作:

  • index early

  • index often

  • index fully

    queries make use of indexes from left to right.

  • index sorts

    If your queries will contain a sort or orderby clause, add the sorted field to your index.

  • commands

The order of fields in an index should be:

  1. First, fields on which you will query for exact values.
  2. Second, fields on which you will sort.
  3. Finally, fields on which you will query for a range of values.

先对sort field部分,进行index,这样能及时保证sort之后的顺序能够得到保证