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 ?
MongoDB can use the intersection of indexes to fulfill queries. For queries that specify compound query conditions, if one index can fulfill a part of a query condition, and another index can fulfill another part of the query condition, then MongoDB can use the intersection of the two indexes to fulfill the query.
Create an index for a MongoDB collection, and specify the order. When you use PyMongo to create an index, you can pair the index name with either a 1 or a -1 integer value to explicitly set the sort order to ascending or descending, respectively.
Unfortunately, you don't.
That feature request has been around for quite a while: https://jira.mongodb.org/browse/SERVER-17853
Hopefully they get to it soon, that would be quite useful.
If the status
field doesn't have null values, you can use
{ partialFilterExpression: { "status": null, "quantity": { $lt: -1 } } } );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With