Issue
im new to mongodb after years with mysql and trying to figure this equivalent query in mongodb with php composer
select * from table where (x > 0 and x < 30) or x = 'half' and sid = 1
$query = [
'$and' => [
[
'sid'=> 1
], ['$and' => [[
'info.x' => [
'$lt' => '30'
]
], [
'info.x' => [
'$gt' => '0'
]
], [
'info.x' => [ /// i want to put this in $or
'half'
]
]]
]
]
];
i want to display all what is greater then 0 and less then 30 or equal to 'half' where sid is 1
thanks
Solution
It must be
db.collection.find({
"$or": [
{ "x": { "$gte": 0, "$lte": 30 }},
{ "x": "half" }
],
"sid": 1
})
Or
$query = [
'$or'=> [
[ 'x'=> [ '$gte'=> 0, '$lte'=> 30 ]],
[ 'x'=> 'half' ]
],
'sid'=> 1
]
Answered By - Ashh
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.