我已经使用cakephp Mysql来Mongo db查询组件,即修改mysql查询进入mongodb,但是当查询有多个括号时代码已经停止工作,我也尝试在http://www.querymongo.com/网站上转换查询同样的问题出现,
SELECT * FROM `matches` WHERE (
( user_id = "550aa8b6156b046c09000000" AND partner_user_id = "55094c30156b049809000004" ) OR
( user_id = "55094c30156b049809000004" AND partner_user_id = "550aa8b6156b046c09000000" ) OR
( doublz_partner_id_a = "55094c30156b049809000004" AND doublz_partner_id_b = "550aa8b6156b046c09000000" ) OR
( doublz_partner_id_a = "550aa8b6156b046c09000000" AND doublz_partner_id_b = "55094c30156b049809000004" )
)
你可以帮我把这个问题转换成mogodb,我是mongodb的新手
答案 0 :(得分:2)
恭喜您不遗余力地查看文档并解决此问题。也许你的“网站”也应该做得更好:
db.matches.find({
"$or": [
{
"user_id": "550aa8b6156b046c09000000",
"partner_id": "55094c30156b049809000004"
},
{
"user_id": "55094c30156b049809000004",
"partner_id": "550aa8b6156b046c09000000"
},
{
"doublz_partner_id_a": "55094c30156b049809000004",
"doublz_partner_id_b": "550aa8b6156b046c09000000"
},
{
"doublz_partner_id_a": "550aa8b6156b046c09000000",
"doublz_partner_id_b": "55094c30156b049809000004"
}
]
})
如您在文档中所述构建$or
查询的方式。
顺便说一句,“谢谢你帮助我”是你的回应。
答案 1 :(得分:1)
db.matches.find({"$or": [
{
"user_id" : "550aa8b6156b046c09000000",
"partner_id" : "55094c30156b049809000004"
},
{
"user_id" : "55094c30156b049809000004",
"partner_id": "550aa8b6156b046c09000000"
},
{
"doublz_partner_id_a" : "55094c30156b049809000004",
"doublz_partner_id_b" : "550aa8b6156b046c09000000"
},
{
"doublz_partner_id_a" : "550aa8b6156b046c09000000",
"doublz_partner_id_b" : "55094c30156b049809000004"
}
]
})