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

675
Views
MongoDB: ¿Cómo encontrar un valor específico en una matriz anidada, si se encuentra, mostrar solo esa matriz, no todo?

ingrese la descripción de la imagen aquí

Estoy tratando de encontrar la identificación "D0182" en la matriz client_id si la encuentra, solo mostrará el documento client_id, pero me muestra el documento completo.

Aquí está mi consulta -

db.getCollection('news').find({"newsSources.client_id":"A0003","date": "2021-01-22"}, {"_id":0,"newsSources.title" :1, "newsSources.client_id":1})

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Puede usar la agregación para filtrar objetos de la matriz.

 db.collection.aggregate([ { "$addFields": { "newsSources": { $filter: { input: "$newsSources", cond: { $in: [ "D0108", "$$this.clientId" ] } } } } } ])

Zona de juegos Mongo en funcionamiento

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