I am having two collections 'MotorDetails' and 'PersonDetails'.Person Id is present is my both collections. I required all items from PersonDetails and only Manufacturer Name from MotorDetails for each person Id. how to join collections in mongodb? I am very new to mongodb so Please help me with this scenario
-
1Possible duplicate of [How do I perform the SQL Join equivalent in MongoDB?](https://stackoverflow.com/questions/2350495/how-do-i-perform-the-sql-join-equivalent-in-mongodb) – felix Mar 30 '18 at 07:19
2 Answers
db.PersonDetails.aggregate([
{$lookup:{
from: "MotorDetails",
localField:"personId",
foreignField:"personIdEquivalentOnMotorDetails",
as:"PersonToManufacturer"
}}
])
Search on stackoverflow(check existing questions) and Google if you want to learn something new. Do not post direct questions where answers are already present on stackoverflow. https://docs.mongodb.com/manual/reference/operator/aggregation/lookup/
You should read , try out yourself and post here only if you stuck at some point.

- 3,197
- 5
- 35
- 55
MongoDB being a NoSQL database does not support concept of relationships Alternatively it facilitates defining relationship using embedded documents.
Also MongoDB has added $lookup
operator which is used to perform left outer join operations into MongoDB Database as a part of aggregation pipeline.
For more detailed description regarding $lookup
operator please refer documentation as mentioned into following URL
https://docs.mongodb.com/manual/reference/operator/aggregation/lookup/

- 3,736
- 1
- 23
- 26