[SERVER-55639] $in with regex has special meaning Created: 30/Mar/21  Updated: 06/Dec/22

Status: Backlog
Project: Core Server
Component/s: Query Language
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Charlie Swanson Assignee: Backlog - Query Optimization
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-55509 {example: /regex/} and {example: {$eq... Backlog
related to SERVER-14595 Allow {$regex: /pattern/} syntax insi... Backlog
is related to SERVER-34012 Planner's logic for taking union of i... Closed
Assigned Teams:
Query Optimization
Operating System: ALL
Participants:

 Description   

When a regex is inside an $in, the regex is actually evaluated against strings, acting like a regex match predicate rather than an equality predicate:

MongoDB Enterprise > db.c.find({a: {$in: [1, /foo/]}})
{ "_id" : ObjectId("5b6b69f6c3d88f417d6971c0"), "a" : /foo/ }
{ "_id" : ObjectId("5b6b69fcc3d88f417d6971c1"), "a" : 1 }
{ "_id" : ObjectId("5b6b6a04c3d88f417d6971c2"), "a" : "foobar" }

This means that $in is not simply syntactic sugar for an $or of equalities. Another unfortunate consequence is that the $lookup join predicate cannot always be expressed as an $in; if there is a regex it must be expressed as an $or.


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