从MySQL到mongosb的等效查询是什么

时间:2019-07-06 19:21:19

标签: php mongodb composer-php

在使用MySQL多年后,我对mongodb感到陌生,并尝试使用php composer在mongodb中计算出等效查询

从(x> 0和x <30)或x ='half'和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'
            ]
        ]]
]

    ]
];

我想显示sid为1时大于0小于30等于'half'的所有内容

谢谢

1 个答案:

答案 0 :(得分:0)

必须是

db.collection.find({
  "$or": [
    { "x": { "$gte": 0, "$lte": 30 }},
    { "x": "half" }
  ],
  "sid": 1
})

$query = [
  '$or'=> [
    [ 'x'=> [ '$gte'=> 0, '$lte'=> 30 ]],
    [ 'x'=> 'half' ]
  ],
  'sid'=> 1
]