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

149
Views
How do I make partial queries in MongoDB?

I'm trying to make queries to my DB -mongo based- but I need them to be partial, lets say, I need the DB to find results when I'm entering something in an input box. For example, lets supose that in my DB there are a lot of users with different names "Paul, Patrick, Pablo, Pantaleon, etc", I need mongo to make a search a throw me the results when in the input I put "pa". I honestly don't know the sintax to do it, because the model.Find({name:""}) just gets the results when you enter the full name....

I'd appreciate a lot if someone can help me with this doubt! Thanks!!!

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

0

I will recommend the operator $regex:

what is $regex: Provides regular expression capabilities for pattern matching strings in queries. MongoDB uses Perl compatible regular expressions (i.e. "PCRE" ) version 8.42 with UTF-8 support.

{name:{$regex: "/pa/",$options:'i'}}

The $options with ‘I’ parameter (which means case insensitivity) specifies that we want to carry out the search no matter if we find the letters ‘Gu’ in lower or upper case.

for know more of it https://www.mongodb.com/docs/manual/reference/operator/query/regex/

about 4 years ago · Juan Pablo Isaza Report

0

As I am able to get your point.

You can try this -

 db.userCollection.find( {name: {$regex: /^pa/}} )

 - will match 'Paul', 'Patrick', 'Pablo', 'Pantaleon', but not 'john', 'prince'.

To understand in detail you can follow mongodb docs

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!