Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

211
Views
mongodb: coincide si un grupo de valores de una matriz está en otra matriz determinada [con agregación]

Estoy buscando una solución desde hace 3 horas y aún no la consigo.

Tengo la siguiente colección:

 {text: 'random text 1', indexes:[1,2] }, {text: 'random text 2', indexes:[1,3] }, {text: 'random text 3', indexes:[2,4] },

y me gustaría tener solo los documentos que tienen todos los valores de índice en una matriz determinada como, por ejemplo [1,2,4]

usando el ejemplo anterior, me gustaría tener el siguiente resultado:

 {text: 'random text 1', indexes:[1,2] }, {text: 'random text 3', indexes:[2,4] },

[1,2] está en [1,2,4] -> Aceptar

[1,3] no está en [1,2,4] debido a 3 -> No está bien

[1,4] está en [1,2,4] -> Aceptar

¿Alguna idea? ¡gracias por tu respuesta! :)

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puedes usar una de estas etapas de $match :

  • Usando $setIsSubset en $expr :
 { "$match": { "$expr": { "$setIsSubset": ["$indexes",[1,2,4]] } } }

Ejemplo aquí

  • Usando $elemMatch y doble negación ( $not y $nin ):
 { "$match": { "indexes": { "$not": { "$elemMatch": { "$nin": [1,2,4] } } } } }

Ejemplo aquí

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!