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

343
Vistas
Consulta MongoDB Array anidado de matrices para basado en múltiples valores
{ 'id' : 1, 'properties':{ 'type': [[0.05, 'education'],[0.6, 'health'],[0.9, 'math']] } }, { 'id' : 1, 'properties':{ 'type': [[0.05, 'education'],[0.01, 'health'],[0.9, 'math']] } },

¿Cómo podría consultar en función de dos parámetros de valor en una matriz anidada de matrices? El objetivo sería devolver el primer documento con properties.type[0] > 0.5 y properties.type[1] == 'health' .

He intentado la siguiente consulta sin suerte.

 db.collection.find({'properties.type': {'$elemMatch':{'$elemMatch':{'$all': [{ "$gt": 0.5, "$lt": 1 },'health']}}}})
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Aquí, intente esto, uso $unwind y $arrayElemAt .

 db.collection.aggregate([ { $unwind: "$properties.type" }, { $match: { "$and": [ { "$expr": { "$gt": [ { $arrayElemAt: [ "$properties.type", 0 ] }, 0.5 ] } }, { "$expr": { "$eq": [ { $arrayElemAt: [ "$properties.type", 1 ] }, "health" ] } } ], } }, { $limit: 1 } ])

Actualizado

 db.collection.aggregate([ { "$addFields": { "orignalObj": "$$ROOT" } }, { $unwind: "$properties.type" }, { $match: { "$and": [ { "$expr": { "$gt": [ { $arrayElemAt: [ "$properties.type", 0 ] }, 0.5 ] } }, { "$expr": { "$eq": [ { $arrayElemAt: [ "$properties.type", 1 ] }, "health" ] } } ], } }, { $limit: 1 }, { $replaceRoot: { newRoot: "$orignalObj" } } ])
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