Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

143
Vistas
Getting a Document With Exactly the Same Keys

If I have a document format in my coms collection:

{
    "recipients": {
        "key1": "value1",
        "key2": "value2",
        "key3": "value3",
    }
}

I want to get all documents which have the exact same keys. In other words, in the above example, if I query for "key1", "key2", "key3", I get the above document. If, on the other hand, I have the following document:

{
    "recipients": {
        "key1": "value1",
        "key2": "value2",
        "key3": "value3",
        "key4": "value4",
    }
}

Querying for "key1", "key2", "key3" should return nothing.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

A quick solution with $exists:

db.collection.find({
   "recipients.key1":{
      $exists:true
   },
   "recipients.key2":{
      $exists:true
   },
   "recipients.key3":{
      $exists:true
   },
   "recipients.key4":{
      $exists:false
   }
})

But this require to know all other possible keys and can be quite painfull to write..

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda