Partial Filter Expressions on unique indexes are unsupported?
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.
It seems that it does not support partial index.
It’s not yet implemented. I’m happy to receive a PR.