Mongodb使用PHP代码复用多个语句

I want a query like the following from mongodb using PHP code:

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

I have tried the following code which is not working:

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

Your query is incorrect, firstly your mrn query should also be in the $and clause, and you should be using $nin (not in array) for your status. Your status query was also surrounded by two array( clauses.

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

Mongodb query:

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

For more detail Click here

You can use MongoDB_DataObject as below:

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