dongpo1216 2019-03-06 12:15
浏览 62

语法问题限制使用find()MongoDB PHP返回的文档数

I'm using find() to fill a php table, and as the database grows I want to limit the results to say 3 documents from the collection. According to the documentation $cursor = $collection->find().limit(3) should accomplish this but no (gives me nothing). Can anyone enlighten me what the issue may be?

edit: error from putty is 'PHP Fatal error: Call to undefined function limit()'

 try{
   $cursor = $collection->find();
    $largest =  0;
   foreach($cursor as $document){
   if ($largest < $document["Time"]) {
       $largest = $document["Time"];
       $longitude = $document["Longitude"];
       $latitude = $document["Latitude"];
   }

   $data .= "<tr>";
   $data .= "<td>" . $document["Time"] . "</td>";
   $data .= "<td>" . $document["Longitude"]."</td>";
   $data .= "<td>" . $document["Latitude"]."</td>";
   $data .= "</tr>";
  }
  $data .= "</tbody>";
  $data .= "</table>";
  echo $data;
  }catch(MongoException $mongoException){
    print $mongoException;
    exit;
}

visual representation, only 2 documents in the collection atm: only 2 documents in the collection atm

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 STM32驱动继电器
    • ¥15 Windows server update services
    • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
    • ¥15 模糊pid与pid仿真结果几乎一样
    • ¥15 java的GUI的运用
    • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
    • ¥15 怎么配置广告联盟瀑布流
    • ¥15 Rstudio 保存代码闪退
    • ¥20 win系统的PYQT程序生成的数据如何放入云服务器阿里云window版?
    • ¥50 invest生境质量模块