[SERVER-22194] partialFilterExpression error - Index with pattern {...} already exists with different options Created: 15/Jan/16  Updated: 15/Jan/16  Resolved: 15/Jan/16

Status: Closed
Project: Core Server
Component/s: Index Maintenance
Affects Version/s: 3.2.0
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Artyom Fanasov Assignee: Kelsey Schubert
Resolution: Duplicate Votes: 2
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-17853 Allow more complex expressions to be ... Backlog
Operating System: ALL
Participants:

 Description   

Developer can't create two same indexes with different partialExpressions, for example:
Developer needs to create indexes with same patterns for types: 'a' and 'b', but not for 'c' and 'd'.
But he's limited (can't use) $in and $or in partialFilterExpression. He also can't create two different indexes with partialFilterExpression:

{type:1}

and partialFilterExpression:

{type:2}

 Comments   
Comment by Kelsey Schubert [ 15/Jan/16 ]

Hi FanAs,

As per Max's comment, I am closing this as a duplicate of SERVER-17853. Please feel vote and watch it and SERVER-18884 for updates.

Kind regards,
Thomas

Comment by Max Hirschhorn [ 15/Jan/16 ]

It is invalid to create two indexes with the same key pattern that only differ in their options. Partial indexes, which are specified by using the partialFilterExpression index option, have the same restriction.

> db.foo.createIndex({a: 1}, {partialFilterExpression: {a: {$type: 1}}})
{
  "createdCollectionAutomatically" : false,
  "numIndexesBefore" : 1,
  "numIndexesAfter" : 2,
  "ok" : 1
}
> db.foo.createIndex({a: 1}, {partialFilterExpression: {a: {$type: 2}}})
{
  "ok" : 0,
  "errmsg" : "Index with name: a_1 already exists with different options",
  "code" : 85
}
> db.foo.createIndex({a: 1}, {unique: true})
{
  "ok" : 0,
  "errmsg" : "Index with name: a_1 already exists with different options",
  "code" : 85
}

I think this ticket is a feature request to be able to use $or in the partialFilterExpression object. If that is the case, then it should be closed as a duplicate of SERVER-17853. For example, being able to create the following partial index.

db.foo.createIndex({a: 1}, {partialFilterExpression: {$or: [{b: {$type: 1}}, {b: {$type: 2}}]}})

Additional notes:

  1. Support for $in in the partialFilterExpression object has been split out from SERVER-17853 and is captured by SERVER-18884.
  2. An array form for $type was proposed in SERVER-20718 that may have made this functionality possible without full support for $or in the partialFilterExpression object.
Comment by Ramon Fernandez Marina [ 15/Jan/16 ]

FanAs, can you please provide the commands being run to create these partial indexes and the exact errors you're getting? That would help us understand more about this issue.

Thanks,
Ramón.

Generated at Thu Feb 08 03:59:41 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.