[SERVER-32733] Support same index definition but with different partial filter expressions Created: 17/Jan/18  Updated: 06/Dec/22  Resolved: 01/Nov/19

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

Type: Bug Priority: Major - P3
Reporter: Luis Torres Aguiar da Costa Assignee: Backlog - Query Team (Inactive)
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-25023 no way to index the same fields with ... Closed
Assigned Teams:
Query
Operating System: ALL
Participants:

 Description   

Currently, it's impossible to create an Index with the same definition (same keys) but a different partial than one that already exists in the collection.
Trying to do it, produces the following error:
The full response is

{
	"ok" : 0.0,
	"errmsg" : "Index: {
		v: 2,
		key: {
			prop: 1,
			timestamp: -1
		},
		name: \"name1.prop\",
		ns: \"db1.col1\",
		partialFilterExpression: {
			name: \"name1\"
		}
	}
	already exists with different options: {
		v: 2,
		key: {
			prop: 1,
			timestamp: -1
		},
		name: \"name2.prop\",
		ns: \"db1.col1\",
		partialFilterExpression: {
			name: \"name2\"
		}
	}",
	"code" : 85,
	"codeName" : "IndexOptionsConflict"
}

My indexes are "dynamic", i.e. they will be added to the collection as Documents are added to another collection. Being so, I need to later add these indexes, but this bug won't allow me so.
Now, the only option is to make the index not partial, but I don't really like that, since it would probably use some unnecessary space.



 Comments   
Comment by Asya Kamsky [ 01/Nov/19 ]

Didn't realize we already had one for this request, marking this one a duplicate.

Comment by Asya Kamsky [ 01/Nov/19 ]

Re-opening to consider as an enhancement request to allow "same" index keys but different partial filter expression (and different name, obviously).

Comment by aleksandar milovanovic [ 15/Jul/19 ]

You should reconsider as this is a genuine usage problem. My usecase: I have a big log collection and I want to expire different types of documents after different amount of time. I need to index by time, to do a partialFilterExpression on the type of document and to choose expireAfterSeconds. Current behavior is very limiting....

Comment by Mark Agarunov [ 18/Jan/18 ]

Hello LuisTAC,

Thank you for the report. Unfortunately, multiple indexes with the same keys that differ only by options are not supported by MongoDB so it would not be possible to create the two indexes as you described.

Thanks,
Mark

Generated at Thu Feb 08 04:31:08 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.