Php 当我将返回结果的数量限制为40时,为什么$cursor返回45个限制
我无法显示$cursor的内容,因为$cursor没有实现_-toString。请让我知道怎么做 现在,$cursor中的查询由以下命令定义: $cursor=$collection->find($rangeQuery,$field) $rangeQuery在哪里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);
$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)