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

118
Views
recuperar el objeto que tiene una matriz vacía de un documento en particular

Tengo algunos documentos de objeto anidado. Y quiero recuperar esos objetos, agruparlos con el objeto anidado que tiene una matriz vacía usando la agregación.

déjame explicarte con más precisión, supongamos que mi colección consiste en los documentos que se dan a continuación---

documento 1

 { "_id": "17202155", "completed": [ "cse331", "cse312" ], "incompleted": [ { "name": "math", "preReq": [] }, { "name": "science", "preReq": [ "bang", "eng", "math" ] }, { "name": "astronomy", "preReq": [ "bang", "eng", "science" ] } ] },

documento 2

 { "_id": "17202157", "completed": [ "cse331", "cse312" ], "incompleted": [ { "name": "math", "preReq": [] }, { "name": "science", "preReq": [] }, { "name": "astronomy", "preReq": [ "bang", "eng", "science" ] } ] }

quiero recuperar el grupo de documentos por la identificación con el objeto que consiste en una matriz vacía. Eso significa que el resultado será...

 { "_id": "17202155", "incompleted": [ { "name": "math", "preReq": [] }, ] }, { "_id": "17202157", "incompleted": [ { "name": "math", "preReq": [] }, { "name": "science", "preReq": [] }, ] }

He usado este código pero no funciona. Aunque soy nuevo en mongodb. por favor, ayúdame--

#mi código-

 db.collection.aggregate({ "$unwind": "$_id" }, { "$group":{"_id": "$incompleted",} }, { "$match": { "_id.preReq": { $size: 0 } } }, )
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

db.collection.aggregate([ { $unwind: "$incompleted" }, { $match: { "incompleted.preReq": [] } }, { $group: { _id: "$_id", incompleted: { $push: "$incompleted" } } } ])

parque infantil mongo

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!