Skip to main content

Posts

Showing posts from July, 2016

$LOOKUP ( Similar to LEFT OUTER JOIN in RDBMS) in MongoDB

In RDBMS, we have different type of joins to join the tables and get the required data from joined tables. As MongoDB is a NO Sql database, MongoDB will not support those type of joins. But we can implement LEFT OUTER JOIN using $lookup function in MongoDB. This function is there in MongoDB 3.2 version. To join two collections we need to have a common field in both the collections. $lookup works with aggregate function only. Syntax: db.collection1.aggregate([  {     $lookup:       {          from:"collection2",          localField:"common field name from collection1",          foreignField:"common field name from collection2",          as:"Alias name for collection2"      }  } ]) Here in above syntax, collection1 -- Collection name which is acts like parent table. collection2 -- Collection name which is acts like child table and this will be joined with collection1. "common field name from collection1" -- Join column