Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

273
Views
How to lowercase field data in MongoDB find()

In my database collection I have two Objects.

[
  {"_id" : 1, name: "notLowercased"},
  {"_id" : 2, name: "lowercased"},
]

I'm using find and $regex to find name that includes some string.

data = await CatalogModel.find({name: {$regex : searcher.toString().toLowerCase()}})

For example my input string is "lowercased".

In result I'm getting an array

[
  {"_id" : 2, name: "lowercased"},
]

But I want to get in result this:

[
  {"_id" : 1, name: "notLowercased"},
  {"_id" : 2, name: "lowercased"},
]

I'm understand that it's happening becase name "notLowercased" not lowercased.

How to lowercase name fields in this request?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can add $options parameter like this: $options: "i".

As explained into docs:

i: Case insensitivity to match upper and lower cases. For an example, see Perform Case-Insensitive Regular Expression Match.

Even you can avoid toLowerCase()

data = await CatalogModel.find({name: {$regex : searcher.toString(), "$options": "i" }})

Example here and without toLowerCase() here

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!