我尝试在PHP中使用this solution分页:
public function getRecords($page, $count, $currentId)
{
$query = ["_id" => ['$gt' => $currentId]]; //what's wrong here?
$cursor = $this->recordsCollection->find($query)->
skip(($page-1) * $count)->
limit($count)->
sort(["_id" => true]);
$result = array();
foreach ($cursor as $doc) {
array_push($result, $doc);
}
return $result;
}
但它返回一个空数组result
。此外,我在没有skip
和limit
的情况下尝试了此查询,但结果仍然是一个空数组。如果$query
为空,一切正常,它会返回收集中的所有记录。
我做错了什么?
解
$query = ["_id" => ['$gt' => new MongoId($currentId)]];
答案 0 :(得分:1)
也许$currentId
类型错误?看看你想要做什么,我认为它应该是MongoId