mongodb

Mongo Partial Filter Expression


I am trying to use create a unique index with a partial filter expression. I've tried all sorts of different things, but I keep getting syntax errors in Compass. Any suggestions on how this should be written. I've tried things like:

{partialFilterExpression: aim_id: {$type: "string"}}
aim_id: {$type: "string"}
aim_id": {$type: "string"}

enter image description here


Solution

  • I just "played" with MongoDB Compass (v1.34.2), and it seems an acceptable incantation for your partialFilterExpression is:

    {"aim_id": {"$type": "string"}}