简体   繁体   中英

can i pass mongodb query as a string in php

I am planning to run mongodb query from php platform text area as picture below where I want to write query like

 array('Chat_time' => array('$gt' => $start, '$lte' => $end))

在此处输入图片说明

and execute like

$m = new MongoClient();
$db = $m->Forensic;
$coll= $db->mobile_
$user_code = $coll->find($_POST['txt_area']));

but cannot execute becuause I think when I convert query to string it cannot understand => as a command.

what would be the best way pass this command as a string and php will understand.

you should write json to your text area. like:

{
    "Chat_time": {
        "$gt" => "xxx",
        "$lte" => "yyy"
    }
}

in php

// json string to array using json_decode
$query = json_decode($_POST['txt_area'], true);
$user_code = $coll->find($query);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM