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

242
Views
Mongodb "like" on multiple fields in aggregation

So I have some user documents that have first names and names. I'd like to offer the possibility to filter them if a given input "looks like" that fullname.

user: {
   firstName: "foo",
   lastName: "name",
   ...
}

Before, I was doing this filter on the javascript side by measuring a "score" of likeness between the input and the fullname, but since I implemented a pagination system I cannot do this anymore.

Now I'd like to find a way to make this on the aggregation-side.

I've found this question and this one, that seems to make the same thing but since they do not use aggregation directly it's difficult to me to link this to my case.

A way of doing that I have been thinking is to use the $where operator in the aggregation and then addField to have the "likness score" with each result of the query, then filter them on their score using the aggregatePaginate options.

But it seems to me I cannot use $where in the aggregation. Any idea ?

Many thanks ! Kev :)

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

For aggregation you can use $function to execute custom code. However that kind of defeats the purpose of pagination as Mongo has to execute this code for each document, additionally it is recommended not to execute js in Mongo as it has somewhat bad performance.

It seems like you're just using the wrong database for the job, If this is a crucial feature I recommend trying a text search db like atlas search or elasticsearch

If changing db is not an option, and this feature is too important to remove or alternate. maybe if your provide additional detail as to how the scoring works it'll be easier to give a full answer.

over 4 years ago · Santiago Trujillo 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!