Before 3.2 mongodb join in mongodb is not possible . But now after mongodb join (left outer join is possible)
db.college.aggregate([
2: {$match:{"college.name" : "Amrapali institude",
3: "college.Id" : "306"}},
4: {$lookup: {
5: from: "courses",
6: as: "courseData",
7: localField: "_id",
8: foreignField: "courses.collegeId"
9: }},
10: {$unwind: "$courseData"},
11: {$project:{"Title":1,
12: "courseName":"$customerData.courseName",
13: "duration" :"$customerData.courseTime"}},
14: ])
what we are doing here is we are all course whose colleageId and colleageName are 306 ans Amrapali institude respectively .THe result of join is each college contain array of its course so we use $unwind to to “flatten” them out .
NOTE: that for forgien key you should do "indexing" on it.
THANKS
More From Oodles
Ready to innovate? Let's get in touch
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Himanshu sharma
Himanshu has marvelous coding skills. In Free time too he loves to do coding and sometimes play Cricket.