0

I want to make a query that does not discriminate by accents or upper or lower case, i have this:

query && pipeline.unshift({
  '$match': { 'name': { '$regex': new RegExp(query, 'i') } }
})

I tried a lot of regex but i don't know how i can use it, can you help me, please

Matt Ke
  • 3,599
  • 12
  • 30
  • 49
Sergi
  • 1

1 Answers1

0
  • $regex add $options : i, case insensitivity to match upper and lower cases.
db.collection.find({
  name: {
    $regex: "sam",
    $options: "i"
  }
})

mongoplayground

YuTing
  • 6,555
  • 2
  • 6
  • 16
  • yes, but this only works with with upper case and lower case, not for insensitivity of accents :( – Sergi Sep 23 '21 at 14:35