Cannot use "$in" for partialFilterExpression in MongoDB 6.0.*

Hello!

Tried to create unique and partial index for my notifications collection through NodeJS driver:

db.notifications.createIndex(
  { userId: 1, date: 1, type: 1 },
  { unique: true, partialFilterExpression: 
    { type: { $in: ["approveDate", "completeDate"] } } 
  },
);

But it hasn’t been created.

Tried to do it through Studio3T:

And got the following error:

Mongo Server error (MongoCommandException): 
Command failed with error 67 (CannotCreateIndex): 
'Error in specification 
{ key: { userId: 1, type: 1, date: 1 }, 
name: "userId_1_type_1_date_1", unique: true, 
partialFilterExpression: { type: { $in: [ "approveDate", "completeDate" ] } }, 
v: 2 } 
:: caused by :: Expression not supported in partial index: type $in [ "approveDate" "completeDate" ]

My MongoDB version is 6.0.8. Upgraded to 6.0.9 - results are the same.
According to the documentation everything should work.
But why it is not? :smiley: What is my mistake here?

1 Like

Most likely you haven’t installed db.adminCommand( { setFeatureCompatibilityVersion: “6.0” } )