【问题标题】:PHP MongoDB $gt Filter Operator with findOne functionPHP MongoDB $gt 过滤运算符与 findOne 功能
【发布时间】:2021-11-17 17:02:21
【问题描述】:

我在使用 PHP 库的 MongoDB 运算符方面遇到了困难。

$data =">1";                     
$val = substr($data ,1);
$filter = ["column_name" => ['$gt' => $val]];   
$test = new \MongoDB\Driver\Query($filter);              
$result = $collection->findOne($test);

//Echo return null value. No data from db

打印 $result 变量

我在运行查询时没有得到任何结果。请帮忙。基本上我只需要知道如何使用 findOne 函数传递 $gt。

【问题讨论】:

  • 你用$val作为数组,然后在上面用substr?也许您想在特定索引上运行 substr
  • 基本上,它适用于不同的阵列。 $data = array ("other"=>">1");, $data = array ("other"=>"

标签: php mongodb


【解决方案1】:

我找到了通过过滤器的解决方案。我修改了代码

$data =">1";                     
$val = substr($data ,1);
$filter = ["column_name" => ['$gt' => $val]];                
$result = $collection->findOne($filter);

基本上我已经把“new\MongoDB\BSON\Query”去掉了,直接把filter传给findOne

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-10-03
    • 2017-04-16
    • 2018-11-22
    • 2018-04-12
    • 1970-01-01
    • 2011-09-27
    • 2019-11-19
    相关资源
    最近更新 更多