本文介绍了我可以将mongodb查询作为字符串传递给php吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正计划从php平台文本区域运行mongodb查询,如下图所示,我想在其中编写查询
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))
并像
$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.
什么是传递此命令的最佳方式,因为字符串和php会理解.
what would be the best way pass this command as a string and php will understand.
推荐答案
,您应该将json写入文本区域.像:
you should write json to your text area. like:
{
"Chat_time": {
"$gt" => "xxx",
"$lte" => "yyy"
}
}
在php
// json string to array using json_decode
$query = json_decode($_POST['txt_area'], true);
$user_code = $coll->find($query);
这篇关于我可以将mongodb查询作为字符串传递给php吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!