How i can insensitive accent an capital letters in agregattion?

158 Views Asked by At

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

1

There are 1 best solutions below

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

mongoplayground