0

我想要使​​用 PHP 代码从 mongodb 进行如下查询:

select * from orders where mrn=1234 and status!=cancelled and status!=delivered and status!=draft

我尝试了以下不起作用的代码:

$filterpatient = array("order.patientinfo.mrn" => $reqresult, '$and' => array( 
    array('order.orderitem.status' => array('$ne' => array('cancelled','delivered')))
    ));
$cursor = $collection->find($filterpatient)->sort(array('_id'=>-1));
4

3 回答 3

1
Try:
$collection->find(array("order.patientinfo.mrn" => $reqresult, 'order.orderitem.status' => array('$nin' => array("cancelled","delivered","draft"))))->sort(array('_id'=>-1));

MongoDB查询:

db.orders.find({"mrn":1234,"status":{"$nin":["cancelled","delivered","draft"]}});

更多详情请点击这里

于 2016-08-02T06:54:41.417 回答
0

您可以使用MongoDB_DataObject如下:

$model = new MongoDB_DataObject();

$model->query("select * from orders where mrn=1234 and status!='cancelled' and status!='delivered' and status!='draft'");

while ($model->fetch()) {
    var_dump($model);
} 

或者:

$model = new MongoDB_DataObject('orders');

$model->whereAdd("mrn=1234 and status!='cancelled' and status!='delivered' and status!='draft'");

$model->find();

while ($model->fetch()) {
    var_dump($model);
}    
于 2017-02-14T02:47:52.127 回答
0

您的查询不正确,首先您的 mrn 查询也应该在 $and 子句中,并且您应该使用$nin(不在数组中)作为您的状态。您的状态查询也被两个array(子句包围。

$filterpatient = array('$and' => array(
    "order.patientinfo.mrn" => $reqresult, 
    "order.orderitem.status" => array('$nin' => array('cancelled','delivered', 'draft'))
));
于 2016-08-01T11:52:37.513 回答