Unique index with empty string

Is there a way to add an index for nonempty string field, for example with Partial index to add to index only if the string field exists and is not empty

I couldn’t find a way to get the length with partial, if I were able to then I could use that to check is greater than 0.
Omit field does not work as “” is zero value for string
$ne : “” does not work as I don’t think $ne/NOT is supported

So is there no way to create a partial index for strings that are not empty?

found this approach that worked for me, didn’t realise that $gt could be used in this way
{ management_ip: 1 },
{ unique: true, partialFilterExpression: { management_ip: { “$exists” : true, “$gt” : “0”, “$type” : “string” }} }

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.