1

I am using Laravel 5.1 as Front End and MongoDB as Back end. Now Problem is when i am performing join query from laravel it will return data only from single collection.

I read mongoDB manual and i know that mongoDB is not RDBMS that’s why it is not support any kind of JOINS.

But in my project it is necessary to get data from two different collection i.e Category and Product.

I know JOINS are possible in mongoDB at Client Side i.e Laravel side using DBRef and Manual Relationship.

I did Manual Relationship between Category.Category_ID and Product.Category_ID, But I don't know how to perform client side code for retrieving Data from both Collections.

I am attaching code of laravel 5.1 for LEFT JOIN which is perfectly run with MySQL but not with MongoDB.

 // Below Code for LEFT JOIN
    $user = DB::table('product')
        ->leftJoin('category', 'product.category_id', '=', 'category.category_id')
        ->where('product.product_id','=','category.category_id')
        ->get();
Ketav
  • 760
  • 1
  • 8
  • 27
  • There are no joins in MongoDB. Just because an ORM/ODM supports a syntax due to it's support for another storage engine does not mean it can support them in any way. The best case scenario is that the product supports the "illusion" of a join by issuing multiple queries. But at best this can never "filter" results from a related collection as it will still need to call all results back to the clent before they can be filtered. You use NoSQL because you are prepared to redesign and rethink the way data is modelled, rather than do it all the same way. – Blakes Seven Oct 06 '15 at 06:30
  • @BlakesSeven: I read below Question and some one give example of JOINS with mongoDB. http://stackoverflow.com/questions/32817900/alternatives-of-join-in-mongodb – Ketav Oct 06 '15 at 07:44
  • It is not true as there are no joins possible. As stated, the features are available when using "relational" storage only. MongoDB has no support at all for joins, and hence the only way a software product can do this is in "emulation", which is not truly a join and does not perform that way. Your correct approach is to think without joins, or to use a relational engine instead. – Blakes Seven Oct 06 '15 at 07:49
  • @BlakesSeven: In My Project More than 50 crore entry will insert that's why I am using MongoDB instead of MySQL. What are the solutions for my problem? Can you elaborate it? – Ketav Oct 06 '15 at 09:03
  • 1
    I have elaborated as much as needed. "No Joins Here", so you need to stop looking for them. Nothing will perform a join. Instead the NoSQL concept is that you generally "pre-join" the data instead, or work around where you can live with pulling in additional information from another query. It is not me who is being unclear here, but yourself. Instead of asking for "joins" then you are perhaps better off explaining the problem you need to solve instead. This is afterall, why we are all using a non-relational solution here in the first place. – Blakes Seven Oct 06 '15 at 09:07
  • 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) – chridam Oct 06 '15 at 12:43
  • @chridam: My collection is near simile to **How do I perform the SQL Join equivalent in MongoDB?** but I don't know how to perform it in larvel 5.1? – Ketav Oct 06 '15 at 13:02
  • This all really depends on the data you are trying to get, but map / reduce would be closest thing to a join and is really target to what your goal is. It mostly functions with aggregates you might need from looking up a join, if you really need to be able to look at one record and then get related data via an object id. True joins don't exist the way they do in a RDBMS – j_mcnally Oct 07 '15 at 05:03
  • If you "need" joins in MongoDB, you are using it wrong. – Daniel W. Dec 27 '18 at 09:30
  • There are no joins in MongoDB using Laravel. check this [enter link description here](https://github.com/jenssegers/laravel-mongodb/issues/624#issuecomment-148651050) – TheGeeky Dec 27 '18 at 09:17

0 Answers0