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

189
Visualizações
Mongo query - fetch records not exactly matches with specified values in filter list

I tried around a bit, but I couldn't find the way to do this with same specific set of elements.

I have the following documents in db,

{
  sys_cd : ["A","B"]
},
{
  sys_cd : ["A", "S"]
},
{
  sys_cd : ["A","B","S"]
},
{
  sys_cd : ["A"]
},
{
  sys_cd : ["B","S"]
},
{
  sys_cd : ["S"]
}

I would like a query that returns only the following records, any doc that contains values other than A, B , A & B should return

{
  sys_cd : ["A", "S"]
},
{
  sys_cd : ["A","B","S"]
},
{
  sys_cd : ["B","S"]
},
{
  sys_cd : ["S"]
}
 

I tried with element match but it's not working.. is there a way to achieve this? Please help..

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Try this:

let inputArray = ["A", "B"]; // or ["B", "A"]

db.myCollection.find({
    sys_cd: {
        $elemMatch: {
            $nin: inputArray
        }
    }
})
over 4 years ago · Santiago Trujillo Relatório

0

Try $nin operator, and add list of arrays,

db.collection.find({
  sys_cd: {
    $nin: [
      ["A"],
      ["B"],
      ["A", "B"]
    ]
  }
})

Playground

over 4 years ago · Santiago Trujillo 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