Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial Filter Expressions on unique indexes are unsupported? #162

Open
ghost opened this issue Sep 16, 2020 · 2 comments
Open

Partial Filter Expressions on unique indexes are unsupported? #162

ghost opened this issue Sep 16, 2020 · 2 comments

Comments

@ghost
Copy link

ghost commented Sep 16, 2020

I have a collection that contains heterogeneous documents. Some documents are uniquely identified by the value of field a (and do not contain field b) and the others are uniquely identified by field b (and do not contain field a).

For example:

{ "a": "foo", "value": "qux" }
{ "b": 1, "value": "quux" }

I have created indexes with the following definitions:

[
  {
    "key": {
      "_id": 1
    },
    "name": "_id_",
    "ns": "my.collection",
    "v": 2
  },
  {
    "key": {
      "a": 1
    },
    "name": "aUniqueIndex",
    "ns": "my.collection",
    "unique": true,
    "partialFilterExpression": {
      "a": {
        "$exists": true
      }
    },
    "v": 2
  },
  {
    "key": {
      "b": 1
    },
    "name": "bUniqueIndex",
    "ns": "my.collection",
    "unique": true,
    "partialFilterExpression": {
      "b": {
        "$exists": true
      }
    },
    "v": 2
  }
]

Inserting the following documents:

{ "a": "foo", "value": "qux" }
{ "b": 1, "value": "quux" }
{ "a": "bar", "value": "quuux" }

... results in a unique constraint violation on bUniqueIndex where the unique value being violated is b: null

These documents should not be present in bUniqueIndex. I looked through the code and could find no mention of partial filter expressions on unique indexes, leading me to believe that they are unsupported at this time.

@msl12
Copy link

msl12 commented Jun 30, 2021

It seems that it does not support partial index.

@bwaldvogel
Copy link
Owner

It’s not yet implemented. I’m happy to receive a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants