Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have try to convert below sql query in mongodb query

SQL
select * from photographer as Ph inner join user as U on U.id=Ph.user_id inner join photographer_review as Pr on Pr.photographer_id=Ph.id inner join photographer_events as Pe on Pe.photographer_id=Ph.id inner  join event as E on E.id =Pe.event_id where (E.date <='22/05/2016' or E.date >='22/05/2016') and Ph.user_id='1' and maximum_distance='15'


What I have tried:

db.photographer.aggregate([{
$match: {
"user_id": uid,
"maximum_distance": {
$gte: mi
}
}
},
{
$lookup: {
from:"user",
localField: "user_id",
foreignField: "_id",
as: "user_data",
}

},{
$lookup: {
from:"photographer_events",
localField: "_id",
foreignField: "photographer_id",
as: "photographer_event_data",
}
}, {$lookup:{
from: "photographer_review",
localField: "_id",
foreignField: "photographer_id",
as: "photographer_data", }
}], function (err, ph_data) {})

i have use this type but i can't join on event collection

Please Help....
Posted
Updated 5-Aug-18 10:47am

1 solution

Try this way...

db.Order.aggregate([
   {
      $lookup:{
         from:"City",
         localField:"City Key",
         foreignField:"City Key",
         as:"lsg"
      }
   },
   {
      $unwind:"$lsg"
   },
   {
      $lookup:{
         from:"Employee",
         localField:"Salesperson Key",
         foreignField:"Employee Key",
         as:"lsg2"
      }
   },
   {
      $unwind:"$lsg2"
   },
   {
      $project:{
         "_id":1,
         "Employee":1,
         "Salesperson Key":1,
         "City":"$lsg.City"
      }
   }
]);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900