Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 当我将返回结果的数量限制为40时,为什么$cursor返回45个限制_Php_Json_Mongodb - Fatal编程技术网

Php 当我将返回结果的数量限制为40时,为什么$cursor返回45个限制

Php 当我将返回结果的数量限制为40时,为什么$cursor返回45个限制,php,json,mongodb,Php,Json,Mongodb,我无法显示$cursor的内容,因为$cursor没有实现_-toString。请让我知道怎么做 现在,$cursor中的查询由以下命令定义: $cursor=$collection->find($rangeQuery,$field) $rangeQuery在哪里 $startplushowmany=$startfrom+$howmany; //$startplush is 40 $cursor=$cursor->limit($startplushowmany);

我无法显示$cursor的内容,因为$cursor没有实现_-toString。请让我知道怎么做

现在,$cursor中的查询由以下命令定义: $cursor=$collection->find($rangeQuery,$field)

$rangeQuery在哪里

    $startplushowmany=$startfrom+$howmany; //$startplush is 40
    $cursor=$cursor->limit($startplushowmany);  

    $numberReturned=$cursor->count();   //$numberReturned is 45

$field是

(string:592) Array
(
    [LongitudeLatitude] => Array
        (
            [$within] => Array
                (
                    [$center] => Array
                        (
                            [0] => Array
                                (
                                    [0] => 106.772835
                                    [1] => -6.186753
                                )

                            [1] => 0.044983732050783
                        )

                )

        )

    [indexContents] => bas
    [Prominent] => Array
        (
            [$gte] => 15
        )

)

您需要使用一个布尔标志来考虑计数限制,否则它会给出实际值 计数

$numberReturned=$cursor->count(true)

引用以下例子:

(string:39) Array
(
    [LongitudeLatitude] => 1
)
<?php

$collection->insert(array('x'=>1));
$collection->insert(array('x'=>2));
$collection->insert(array('x'=>3));

$cursor = $collection->find();

var_dump($cursor->count());
var_dump($cursor->count(true));

$cursor->limit(2);

var_dump($cursor->count());
var_dump($cursor->count(true));

?>
int(3)
int(3)
int(3)
int(2)