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

208
Views
¿Cómo puedo pasar una variable, por ejemplo, /variable/, en una consulta de Mongo?

Estoy tratando de pasar searchTerm desde una variable, ¿cómo podría lograr esto, por favor?

 const mongoquery = { description: { $in: [ /searchTerm/ ] } };

Inicialmente probé con:

 const mongoquery = { description: { $in: [ `/${searchTerm}/` ] } };

Pero esto no funciona porque los ` están incluidos en la cadena:

 { description: { '$in': [ '/FAB/' ] } }
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Puede usar RegExp en searchTerm como como

 const mongoquery = { description: new RegExp(searchTerm, "i") };

Para la búsqueda de Me gusta, puede usar Me gusta como

 const mongoquery = { description: new RegExp("^" + searchTerm + "$", "i") }; OR const mongoquery = { description: new RegExp(searchTerm + "$", "i") };
about 4 years ago · Juan Pablo Isaza Report

0

Puede usar el método RegExp ,

 const mongoquery = { description: { $in: [ new RegExp(searchTerm) ] } };
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!