Anurag
Anurag

Reputation: 31

How to make Mongoose query case insensitive?

      const userExists = await Users.exists({ username: username });

How can I make this userExists boolean case insensitive?

**

It is resulting false if I enter anurag,Anurag,aNurag

**

Upvotes: 1

Views: 2475

Answers (1)

Damian Busz
Damian Busz

Reputation: 1848

You will need to use Regex

const userExists = await Users.exists({ username: { '$regex': username, $options: 'i' } })

i in options stands for case-insensitive.

Upvotes: 4

Related Questions