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
MongoDB sort the query by the first field, then by the second

So I'm trying to sort my query:

await Content.find({
    $text: {$search: `\"${query}\"`},
}

It querys in the title, text and author of a document. Basically, I want to order it by the fields, so that if the searched word is in the title field it is on the first place and so on with the author and text.

Is this even possible with mongodb or do I have to do this on the Javascript side?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

In most search technologies, have an option called boost. If you take solr, elasticsearch there you could apply this option to assign a priority.

It is called weights in mongo.

Reference

CreateIndex takes extra object where weight of each field part of text index can be specified. Hence the score of the resulted document multiplied by this weight factor.

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!