MongoDB is relational, you just need to rewire your brain

LEFT JOIN / LEFT OUTER JOIN

What is equalization?

SELECT orders.id, users.first_name, users.surname, products.name as 'product name'FROM ordersINNER JOIN users on orders.user_id = users.id//orders.user_id = users.id is equalization

How to do it in MongoDB?

db.purchases.distinct(‘products’)
db.purchases,aggregate({$match:{customer:{$in:['mike','tom']}},$group:{name:'$customer',expenditure:{$add:'$total'}},$sort:{ expenditure:- 1}})

$match

customer:{$in:['mike','tom']} means 

$group

$sort

Understanding $lookup

db.orders.aggregate([{    $match:{//narrow the dataset of orders},$lookup:
{
from: "inventory",
localField: "field in orders for equilization",
foreignField: "field in inventory for equilization",
as: "inventory_docs"
}
}
])
[{
price:'bla bla bla'
customer:'bla bla bla'
date:'bla bla bla'
inventory_docs:{

inventory document corresponding to the order localfield
which matched with foreignField (given field of inventory)
}},
{
price:'bla bla bla'
customer:'bla bla bla'
date:'bla bla bla'
inventory_docs:{

inventory document corresponding to the order localfield
which matched with foreignField (given field of inventory)
}}
]

RIGHT JOIN

INNER JOIN

How it can be implemented on MongoDB

There is hope

$in:[field values of right table]
//posts collection[
{pageTitle:'lorem', postContent:'lorem came before ipsum'},
{pageTitle:'programming', postContent:'react is old'},
{pageTitle:'fashion', postContent:'too complicated'},
]//pagesLiked Collection
[
{pageTitle:lorem, user:'bananaPants',liked:true},
{pageTitle:programming, user:'bananaPants',liked:true},{pageTitle:lorem, user:'bananaShirt',liked:true},
{pageTitle:lorem, user:'bananaJeans',liked:true}
]
SELECT posts.content FROM posts INNER JOIN pagesLiked ON posts.pageTitle= pagesLiked.pageTitle WHERE pagesLiked.user'%{$loggedInUser}%' ";
let pagesLiked = await db.pagesLikes.find({user:loggedInUser})
pagesLiked = pagesLiked.map(item=>{ return item.pageTitle })
let posts = await db.posts.find({pageTitle: {$in:pagesLiked}})

You may ask why doesn’t mongo DB has an abstracted method to encapsulate all of this?

Lets say you have a users collection that has the following document{
userData:{
username:'bananaPants',
password:'hashedData',
fullName:'sir banana pants'
},
signupData:'some data',
banned:false
}
db.users.find({userData.username:'bananaPants'})

The Dont’s

//image this document is part of a collection named mostStuff{
userData:{username:'banana',pass:'hashed'}
goodGuy:False,
articles:{
aTitle:{content:'sun is yellow'},
anotherTitle: {content:'I like emoji'}
}}

Resources that helped me

Finding Magic.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store