For example, I created this index:

db.test.createIndex({field1:1}, {partialFilterExpression:{field2:{$gt:10}}})

Index created successfully. Then I want to create second index:

db.test.createIndex({field1:1}, {partialFilterExpression:{field2:{$lte:10}}}

But above will give error IndexOptionsConflict, but no error details, only dumps the index object.

I have tested to create such indexes on PostgreSQL and it works. How can I do this in MongoDB?

  • You cannot create an index with the same field but different options on MongoDB. See SERVER-25023 for possible workarounds. – kevinadi Nov 13 at 0:17

Sadly, a restriction of MongoDB:


In MongoDB, you cannot create multiple versions of an index that differ only in the options. As such, you cannot create multiple partial indexes that differ only by the filter expression.

Right now, you can only do this:

db.test.createIndex({field1:1}, {partialFilterExpression:{field2:{$gt:10,$lte:10}}})

Or use composite indexes with a placeholder field:

db.test.createIndex({field1:1, never_use_this_field1: 1}, {partialFilterExpression:{field2:{$gt:10}}})
db.test.createIndex({field1:1, never_use_this_field2: 1}, {partialFilterExpression:{field2:{$lte:10}}}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.