0

I have a collection containing usernames. If a user searches for "joe", I want it to return "Joe", and any case-different variants (i.e. "jOe", etc.).

I'm using monk to implement mongodb queries in my node.js application - but the documentation has no mention of case insensitive queries, nor does it have any implementation of collations.

I am aware that regex can be used (and works), but it seems to go against the advice of the mongo documentation. Is there a regexless way of doing this in node.js implementations of MongoDB?

I'm unsure as to how I would implement a query like this - Any help would be appreciated.

3
  • Looks like a dupe of stackoverflow.com/questions/1863399/…. Lots of options in the answers there. Commented Jan 11, 2020 at 2:00
  • Also stackoverflow.com/questions/22021576/… may help you Commented Jan 11, 2020 at 2:01
  • HI, yes - I've seen these posts and they don't work formally with node.js implementations of mongoDB (namely monk - but also mongoose), as they don't have implementations for collations. The remaining option is regex, which is against mongoDB's advice. Commented Jan 11, 2020 at 2:04

1 Answer 1

2

MongoDB supports text search - as long as the field has the appropriate index you can leverage the $text operator which supports a caseSensitive option.

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.