白森 发表于 2018-10-28 08:16:50

PHP与MONGODB的结果集操作

  MongoCursor MongoCollection::find(array $query,array $fields)
  大家应该有发现,在以上的标准查询指令中,只有查询条件和要查询的字段,那么“分页”、“排序”怎么办呢?
  mongoDB其实是分两步来做的,第一步用find()来获取符合条件的结果,第二步才是分页、排序、分组等等。
  获得结果数量:
  http://www.php.net/manual/en/mongocursor.count.php
  $cursor = $cull->find();
  $count = $cursor->count();
  对结果集排序:
  http://www.php.net/manual/en/mongocursor.sort.php
  $cursor = $cull->find();
  $cursor = $cursor->sort(array("a" => 1));
  分页获取结果集:
  http://www.php.net/manual/en/mongocursor.skip.php
  http://www.php.net/manual/en/mongocursor.limit.php
  $cursor = $cull->find();
  $cursor = $cursor->sort(array("a" => 1));
  $cursor = $cursor->skip(10)->limiti(20);

页: [1]
查看完整版本: PHP与MONGODB的结果集操作