[SERVER-44328] multikeys Index unbounded with $elemMatch Created: 30/Oct/19  Updated: 27/Oct/23  Resolved: 31/Oct/19

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

Type: Bug Priority: Major - P3
Reporter: FRANCK LEFEBURE Assignee: Unassigned
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Participants:

 Description   

I found many closed issues about multikeys index bounds but I can't find an opened one for the 3.6.13

Regarding this index :

 

{
    "activities.metadatas.joinValue" : 1,
    "activities.metadatas.joinStart" : 1,
    "activities.metadatas.joinEnd" : 1
}

And this query :

 

 

{'activities.metadatas': {'$elemMatch':{
    'joinValue':'4559157', 
    "joinStart": { "$gte": ISODate("2019-10-29T10:29:24.860Z"), 
                   "$lt": ISODate("2019-10-29T10:29:26.870Z") }}}
}

Then the query planner uses the previous index with theses bounds :

 

 

{
	"activities.metadatas.joinValue": [
		"[\"4559157\", \"4559157\"]"
	],
	"activities.metadatas.joinStart": [
		"[new Date(1572344964860), new Date(1572344966870))"
	],
	"activities.metadatas.joinEnd": [
		"[MinKey, MaxKey]"
	]
}

==> OK

Now with this query variant

 

{'activities':{'$elemMatch':{'metadatas': {'$elemMatch':{
	'joinValue':'4559157','name': 'customer_id',
	"joinStart": {
		"$gte": ISODate("2019-10-29T10:29:24.860Z"),
		"$lt": ISODate("2019-10-29T10:29:26.870Z")
}}}}}}

Then the bounds are :

 

 

{ 
"activities.metadatas.joinValue": [ "[\"4559157\", \"4559157\"]" ], "activities.metadatas.joinStart": [ "[MinKey, MaxKey]" ], "activities.metadatas.joinEnd": [ "[MinKey, MaxKey]" ]
}

=> timeout..

 

 

 

 



 Comments   
Comment by Carl Champain (Inactive) [ 31/Oct/19 ]

Hi franck.lefebure@gmail.com,

No problem, and thanks anyway for the report. I'm glad our documentation was useful!
I'm closing this ticket.

Kind regards,
Carl

Comment by FRANCK LEFEBURE [ 31/Oct/19 ]

OMG I just see this https://docs.mongodb.com/manual/core/multikey-index-bounds/ section :

As such, MongoDB cannot compound the bounds, and the "ratings.scores.q2" field will be unconstrained during the index scan. To compound the bounds, the query must use $elemMatch on the path "ratings.scores"

{{}}

So it's documented. Sorry for the noise

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