Anurag Gupta
Anurag Gupta

Reputation: 31

In mongodb how to ignore case sentive case?

db.tasks.find({ name: {$regex: '^T',$options: "x"}},{name:1});

it working fine when I enter Capital Letter for example T but when I enter lower case letter for example it is not working

db.tasks.find({name: {$regex: '^[a-zA-z]T',$options: "x" }}, {name:1});

Please help me

Upvotes: 1

Views: 1323

Answers (1)

Ravi kumar
Ravi kumar

Reputation: 330

I would suggest if you're using mongo3X version please go for case-insensitive collation index.

MongoDB introduced this concept in it's 3.4 version. You can use this case-insensitive search over even high volumes of data.

Please refer this link to get more idea on how it works.

Moreover you can use regex as well, But it is purely depends on your requirements how frequently you need to query for case-sensitive text.

Hope this will helpful for you.!

Upvotes: 1

Related Questions