gpt4 book ai didi

php - 我可以在 php 中将 mongodb 查询作为字符串传递吗

转载 作者:行者123 更新时间:2023-11-28 05:07:18 25 4
gpt4 key购买 nike

我计划从 php 平台文本区域运行 mongodb 查询,如下图所示,我想在其中编写查询,例如

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

enter image description here

并像

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

但无法执行,因为我认为当我将查询转换为字符串时,它无法将 => 理解为命令。

将此命令作为字符串传递并且 php 能够理解的最佳方式是什么。

最佳答案

您应该将 json 写入文本区域。像:

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

关于php - 我可以在 php 中将 mongodb 查询作为字符串传递吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41635040/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com