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

258
Visualizações
find document node using string based lower case or upper case

I have mongo db data like this,

{
  "_id": { "$oid": "62bd29431e2e2feca0c53cd2" },
  "inspectionType": "hai2",
  "interval": 1,
  "companyId": { "$oid": "62b4aee8e86962a28632a01a" },
  "createdAt": { "$date": "2022-06-30T04:40:35.946Z" },
  "updatedAt": { "$date": "2022-06-30T04:40:35.946Z" },
  "__v": 0
}

User Input String is : inspection = 'Hai2' Or 'hai2'

I have to find the that document using above the string . I have used below the query but getting empty response.

return db.inspectionCollection
    .find({ inspectionType: inspection, companyId })
    .sort({ updatedAt: -1 })
    .lean(true)
    .catch((err: Error) => {
      logger.error(err);
      return [];
    });

So, What exact query format to getting the documents using string ?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Would suggest using $regex with options "im" which matches with case-insensitive (i) and full string (from start to end) (m).

db.collection.find({
  inspectionType: {
    $regex: "hai2",
    $options: "mi"
  },
  companyId: {
    "$oid": "62b4aee8e86962a28632a01a"
  }
})

Sample Mongo Playground

return db.inspectionCollection
    .find({ 
        inspectionType: {
            $regex: inspection, 
            $options: "im"
        },
        companyId: /* Value with ObjectId type */
    })
    .sort({ updatedAt: -1 })
    .lean(true)
    .catch((err: Error) => {
      logger.error(err);
      return [];
    });
about 4 years ago · Juan Pablo Isaza Relatório
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