Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-55639

$in with regex has special meaning

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Query Language
    • None
    • Query Optimization
    • ALL

      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.

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            charlie.swanson@mongodb.com Charlie Swanson
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated: