【问题标题】:greater than symbol for find() method in php7 mongodbphp7 mongodb中find()方法的大于符号
【发布时间】:2017-02-03 19:54:16
【问题描述】:

我正在开发一个 php-mongodb 项目。我已经使用 composer 安装了 php-mongodb 驱动程序。连接工作正常。

用于任何指导的参考链接: http://mongodb.github.io/mongo-php-library/tutorial/crud/#crud-operationshttp://php.net/manual/en/mongocollection.find.php

除了那些,我找不到太多可靠的 php-7 理论。 如何使用 php-7 触发查询以从数据库中获取大于指定数字的结果?

我试过的代码是:

$rs=$collection->find(['$gte'=>['avg'=>50]]);

这不起作用。它产生的错误是:

Fatal error: Uncaught MongoDB\Driver\Exception\ConnectionException: unknown top level operator: $gte in /var/www/example.com/public_html/vendor/mongodb/mongodb/src/Operation/Find.php:180 Stack trace: #0 /var/www/example.com/public_html/vendor/mongodb/mongodb/src/Operation/Find.php(180): MongoDB\Driver\Server->executeQuery('training.tbl', Object(MongoDB\Driver\Query), Object(MongoDB\Driver\ReadPreference))#1 /var/www/example.com/public_html/vendor/mongodb/mongodb/src/Collection.php(437): MongoDB\Operation\Find->execute(Object(MongoDB\Driver\Server)) #2 /var/www/example.com/public_html/list.php(5): MongoDB\Collection->find(Array) #3 {main} thrown in /var/www/example.com/public_html/vendor/mongodb/mongodb/src/Operation/Find.php on line 180

【问题讨论】:

    标签: mongodb find php-7


    【解决方案1】:

    here 中找到这个答案

    // 搜索 5 的文档

    $rangeQuery = array('x' => array( '$gt' => 5, '$lt' => 20 ));
    

    对于上面的例子,答案是:

    $rangeQuery = ['avg' => ['$gt' => '50' ]];
    $rs=$collection->find($rangeQuery);
    

    【讨论】:

    • 我正在与docs.mongodb.com/php-library/v1.2 合作,但他们没有任何示例。我正在搜索并发现您的答案在这种情况下也很有帮助。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-26
    相关资源
    最近更新 更多