Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-27528

partialFilterCondition index ignores $exists:true condition

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.2.10, 3.4.1
    • Component/s: Querying
    • Labels:
      None
    • ALL

      I have a collection with a partial index created using the following command:

      db.Nodes.createIndex({spaceOwner:1, key:1}, {unique:true, partialFilterCondition: {spaceOwner:{$exists:true}}});
      

      As you can see, I'm trying to set up a unique partial constraint anytime the field "spaceOwner" exists. The combination of spaceOwner / key is always unique anytime the field spaceOwner exists. This is guaranteed by the application. However, I keep getting duplicate key exceptions for when the spaceOwner field doesn't exist which makes sense because in that scenario, there will indeed be duplicates but the index should only check when the spaceOwner key exists, which it doesn't seem to be doing.

      Here is an example stack trace:

      com.mongodb.MongoWriteException: E11000 duplicate key error collection: NubiDo2.Nodes index: spaceOwner_1_key_1 dup key: { : null, : "tasks" }
      	at com.mongodb.MongoCollectionImpl.executeSingleWriteRequest(MongoCollectionImpl.java:487)
      	at com.mongodb.MongoCollectionImpl.update(MongoCollectionImpl.java:474)
      	at com.mongodb.MongoCollectionImpl.updateOne(MongoCollectionImpl.java:325)
      ...
      ...
      

            Assignee:
            kelsey.schubert@mongodb.com Kelsey Schubert
            Reporter:
            kamalkalra Kamal Kalra
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: