mongodb和php的用法详解(2)

$coll = $mo->db->coll; $c = array('a'=>1,'s'=>array('$lt'=>100)); $newobj = array('e'=>'f','x'=>'y'); $options = array('safe'=>true,'multiple'=>true); $rs = $coll->remove($c,$newobj,$options);

查询collection获得单条记录(MongoCollection类)

$coll = $mo->db->coll; $query = array('s'=>array('$lt'=>100)); $fields = array('a'=>true,'b'=>true); $rs = $coll->findOne($query,$fields);

查询collection获得多条记录(MongoCollection类)

$coll = $mo->db->coll; $query = array('s'=>array('$lt'=>100)); $fields = array('a'=>true,'b'=>true); $cursor = $coll->find($query,$fields); //排序 $cursor->sort(array(‘字段'=>-1));(-1倒序,1正序) //跳过部分记录 $cursor->skip(100);跳过100行 //只显示部分记录 $cursor->limit(100);只显示100行 返回一个游标记录对象MongoCursor。

针对游标对象MongoCursor的操作(MongoCursor类)

$cursor = $coll->find($query,$fields); while($cursor->hasNext()){ $r = $cursor->getNext(); var_dump($r); } //或者 $cursor = $coll->find($query,$fields); foreache($cursor as $k=>$v){ var_dump($v); } //或者 $cursor = $coll->find($query,$fields); $array= iterator_to_array($cursor);

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/a228235a9f3c23b1bdb12bacff28f61b.html