What are the limitations of partial indexes?

后端 未结 1 1518
面向向阳花
面向向阳花 2021-01-05 08:34

The latest version of MongoDB (v3.2) adds support for partial (filtered) indexes. You supply a filter when you create the index and that filter determines which documents wi

1条回答
  •  有刺的猬
    2021-01-05 09:00

    Can I use any filter expression?

    No, partial indexes support only a subset of the operators in the filter used. The only supported operators are: $AND (only at the top level), $EQ, $LT, $LTE, $GT, $GTE, $EXISTS and the TYPE_OPERATOR.

    That leaves out, for example $NOT, $REGEX, $OR, etc.

    You can see that in the source for MongoDB here.

    What are those limitations?

    There are also some general limitations on partial indexes:

    • _id indexes can't be partial indexes.
    • Sparse indexes can't be partial indexes.
    • Shard key indexes can't be partial indexes.
    • Partial indexes aren't supported in versions earlier than 3.2.

    0 讨论(0)
提交回复
热议问题