1

I am new in mongoDB. I am facing Problem with mongoDB. That is "How do i give relationship between two collections in mongoDB?"

I read manual of mongoDB that mention mongoDB is not a RDBMS and mongoDB is not support Any kind of JOINS. But i want to know Alternatives of JOINS in mongoDB.

  • 1
    Schema design in MongoDB is driven by your application's data access pattern.Same for designing relations.If you can give some insight on data access pattern ,it will help.Or you are asking in a general question? – faisal_kk Sep 28 '15 at 07:56
  • 2
    I doubt that you read the mongodb docs. Relations are shown quite often. There is a [whole section called "data modeling"](http://docs.mongodb.org/manual/data-modeling/) which explain in depth(!!!) how to model any conceivable relationship. You might want to read [How do I ask a good question](http://stackoverflow.com/help/how-to-ask), which enhances the probability for getting a useful answer _drastically_. You might find [ESR](https://en.m.wikipedia.org/wiki/Eric_S._Raymond)'s excellent essay [How To Ask Questions The Smart Way](http://catb.org/~esr/faqs/smart-questions.html) helpful, too. – Markus W Mahlberg Sep 28 '15 at 08:09
  • possible duplicate of [How do I perform the SQL Join equivalent in MongoDB?](http://stackoverflow.com/questions/2350495/how-do-i-perform-the-sql-join-equivalent-in-mongodb) – Philipp Sep 28 '15 at 08:39
  • @Philipp, I did all steps mention in How do I perform the SQL Join equivalent in MongoDB? but when i update master table then update is not effect on slave table. – Više Antoniyo Sep 28 '15 at 09:38
  • 1
    @VišeAntoniyo There are no tables in MongoDB, only collections. There are no such thing as master collections and slave collections either. But when you describe how your documents look, what exactly you want to do, how you try to do it, and what it does instead of what you expect, we might be able to help you. Please post this as a new question. – Philipp Sep 28 '15 at 10:43
  • @Philipp I am using Laravel 5.1 as a Framework and MongoDB as a Backend. In My Project More than 50 crore entry will insert thats why i am using MongoDB instead of MySQL. But when i apply inner join from laravel it will display data of Product Collection not Category Collection. My Requirement is get all Detail of Product Collection and name of Category from Category Collection. – Više Antoniyo Sep 28 '15 at 10:56

2 Answers2

0

From MongoDb v3.2 , new $lookup operator was introduced to perform joins in MongoDb . This works as sql left join and its documentation can be found at

https://docs.mongodb.com/master/reference/operator/aggregation/lookup/#pipe._S_lookup

TharunRaja
  • 707
  • 7
  • 28
0

You can get data from two or more collection use aggregate method suing $lookup. db.test.aggregate([{$lookup:{from:"test1",localField:"user_id",foreignField:"emp_id",as:"data"}}]).pretty(); Here test is 1st collection, test1 is 2nd collection and user_id and emp_id are join key from respective collections. And we will get result data in data key as the result.

Vik2696
  • 347
  • 2
  • 7