2016-08-01 23 views
0

我要像使用PHP代碼的MongoDB下面的查詢語句:MongoDB的多,並使用PHP代碼

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)); 

回答

0

您查詢是不正確的,首先你的mrn查詢也應該在$和子句中,你應該使用$nin(不是數組)來表示你的狀態。您的狀態查詢也被兩個array(子句包圍。

$filterpatient = array('$and' => array(
    "order.patientinfo.mrn" => $reqresult, 
    "order.orderitem.status" => array('$nin' => array('cancelled','delivered', 'draft')) 
)); 
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"]}}); 

更多細節Click here

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); 
} 

OR:

$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); 
}