0

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

3 Answers 3

1
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

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.