4

I'm trying to write a MongoDB query with Mongoose in Node.JS to get all names in a database matching a certain name. I would like that the query ignores the case and accents.

I looked around on the internet but couldn't find a query that does that.

MongoDB queries support regexes so that's what I'm trying to do.

This is what I have now. It works but doesn't match if the query or the queried string has accents and the other doesn't.

Passenger_record.find({$and: [{"FIRSTNAME": { $regex:req.query["firstname"], $options: 'i' }},{"LASTNAME": { $regex:req.query["lastname"], $options: 'i' }}]}).exec(function (err, person)

Thanks for your help.

1 Answer 1

1

Check this out, Programatic Accent Reduction in JavaScript (aka text normalization or unaccenting)

You'll find a function to build an accent insensitive regexp.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.