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

205
Views
Construyendo un criterio en mongoDB que no devuelve los valores adecuados

Estoy tratando de crear un criterio que filtre las entradas en la base de datos, pero no obtengo los resultados adecuados al filtrar el género. (el texto parece funcionar, pero no estoy seguro de si el código admitirá ambos filtros).

Esta es mi función buildCriteria, el registro de la consola devuelve los valores adecuados.

 function _buildCriteria(filterBy) { const criteria = {}; const { text, genre } = filterBy; console.log('genre:', genre); if (text) { const txtCriteria = { $regex: text, $options: 'i' }; criteria.name = txtCriteria; } if (genre) { criteria.genre = { $eq: genre }; } return criteria; }

Esta es la función de consulta:

 async function query(filterBy) { try { const criteria = _buildCriteria(filterBy); const collection = await dbService.getCollection('tab'); const tabs = await collection.find(criteria).toArray(); return tabs; } catch (err) { logger.error('Can not find tabs', err); throw err; } }

Agradecería mucho su ayuda!

about 4 years ago · Juan Pablo Isaza
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!