mongo 查询 最新一条数据

 public function selectNum(){
        $m = new MongoDB\Driver\Manager('mongodb://0.0.0.0:27017');

        $filter = array();
        $options = array(
            'sort' => ['_id' => -1],
            'limit' => 1,
        );
        $query = new  MongoDB\Driver\Query ($filter, $options);
        $cursor = $m->executeQuery('BrandGazette.catalogueInfo', $query);
        foreach ($cursor as $document) {
            $arr = $this->object2array($document);
            return $arr['ann_num'];
        }

    }

你可能感兴趣的:(php,mongo)