how to create a partial index with $exists: false condition?

Viewed 1190

I want to create this partial index:

db.mycollection.createIndex( 
  {"firstname": 1, "lastname": 1}, 
  { partialFilterExpression: { "status": {$exists: false}, "quantity": { $lt: -1 } } } ); 

but i receive this error:

unsupported expression in partial index: $not\n status exists\n"

How can I do ?

2 Answers

If the status field doesn't have null values, you can use

{ partialFilterExpression: { "status": null, "quantity": { $lt: -1 } } } ); 
Related