Unique index in mongoDB 3.2 ignoring null values

前端 未结 4 1500
余生分开走
余生分开走 2021-02-07 00:24

I want to add the unique index to a field ignoring null values in the unique indexed field and ignoring the documents that are filtered based on partialFilterExpression.

4条回答
  •  情深已故
    2021-02-07 00:34

    Yes, you can create partial index in MongoDB 3.2

    Please see https://docs.mongodb.org/manual/core/index-partial/#index-type-partial

    MongoDB recommend usage of partial index over sparse index. I'll suggest you to drop your sparse index in favor of partial index.

提交回复
热议问题