Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

207
Visualizações
Building a criteria in mongoDB that doesn't return the proper values

I'm trying to builda criteria that would filter the entries in the DB ,yet i'm not getting the proper results when filtering the genre. (the text seems to work but i'm not sure if the code will support both filters).

This is my buildCriteria function, console logging returns the proper values.

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;
}

This is the query function :

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;
  }
}

Would appreciate your help greatly!

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda