Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

MongoDB inserting child document on ID reference

I migrated my SQL database into a MongoDB database for a project. It migrated the foreign keys as the ID’s that were already there. For example I have these two columns linked through the driversId:
enter image description here

My question is how do I get the driver as a document in the driver_standings collection? Thanks in advance!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

use $lookup aggregation operator

db.driver_standings.aggregate([{
  $lookup: {
    from: "drivers",
    localField: "driverId",
    foreignField: "driverId",
    as: "driver"
  }
}])
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading