如何加入多个集合并使用mongodb中的where子句

如何加入多个集合并使用mongodb中的where子句

本文介绍了如何加入多个集合并使用mongodb中的where子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在mongodb查询中转换下面的sql查询



i have try to convert below sql query in mongodb query

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'





我尝试过:



db.photographer.aggregate([{

$匹配:{

user_id:uid,

maximum_distance:{

$ gte:mi

}

}

},

{

$ lookup:{

来自:user,

localField: user_id,

foreignField:_ id,

as:user_data,

}



},{

$查询:{

来自:photographer_events,

localField:_ id,

foreignField:photographer_id,

as:photographer_event_data,

}

},{$ lookup :{

来自:photographer_review,

localField:_ id,

foreignField:photographer_id,

as:photographer_data,}

}],函数(错误,ph_data){})



i使用此类型但我无法参加活动收集



请帮助....



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....

推荐答案




这篇关于如何加入多个集合并使用mongodb中的where子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 01:02