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

270
Views
¿Cómo puedo combinar dos colecciones en mongoDB y también cumplir con las siguientes condiciones?

Nota : Cada colección contiene 96.5k documentos y cada colección tiene estos campos:

 { "name": "variable1", "startTime": "variable2", "endTime": "variable3", "classes": "variable4", "section": "variable" }

Tengo 2 colecciones. Tengo que comparar estas 2 colecciones y tengo que averiguar si algunos campos específicos (aquí quiero nombre, hora de inicio, hora de finalización) de los documentos son los mismos en ambas colecciones.

Mi enfoque fue unir estas 2 colecciones y luego usar $ lookup. También probé la siguiente consulta pero no funcionó. Por favor, ayúdame.

 col1.aggregate([ { "$unionWith": {"col1": "col2"} }, { "$group": { "_id": { "Name": "$Name", "startTime": "$startTime", "endTime": "$endTime" }, "count": {"$sum": 1}, "doc": {"$first": "$$ROOT"} } }, { "$match": {"$expr": {"$gt": ["$count", 1]}} }, { "$replaceRoot": {"newRoot": "$doc"} }, { "$out": "newCollectionWithDuplicates" } ])
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Su enfoque está bien, solo tiene un error de sintaxis menor en su $unionWith , se supone que debe ser así:

 { "$unionWith": { coll: "col2", pipeline: [] } }

Parque infantil Mongo

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!