//** ???????? **/
echo ‘count:’.$collection->count().”<br>”; #???
echo ‘count:’.$collection->count(array(‘type’=>’user’)).”<br>”; #???‘type’ ? user ????
echo ‘count:’.$collection->count(array(‘age’=>array(‘$gt’=>50??’$lte’=>74))).”<br>”; #??????50С?????74
echo ‘count:’.$collection->find()->limit(5)->skip(0)->count(true).”<br>”; #??????????????
/**
* ?:$gt??????$gte?????????$lt?С???$lte?С??????$ne????????$exists??????
*/
//** ??????????м?? **/
$cursor = $collection->find()->snapshot();
foreach ($cursor as $id => $value) {
echo “$id: “; var_dump($value); echo “<br>”;
}
/**
* ???:
* ??????????find()?????????$cursor?α????????α???????.
* ???仰???????find()?????????α???????????????????з?????????????????collection???????Щ??????$cursor ???.
* ???????????$cursor???????????仯?????????????
* $cursor = $collection->find();
*/
//** ?????????? **/
$cursor = $collection->findOne();
/**
* ???:findOne()??y???????????snapshot()??fields()?????;
*/
//** ?????????? age??type ?в???? **/
$cursor = $collection->find()->fields(array(“age”=>false??”type”=>false));
$cursor = $collection->find()->fields(array(“user”=>true)); //????user ??
/**
* ??????д?????:$cursor->fields(array(“age”=>true??”type”=>false));
*/
//** ???????? (????type??age???) and age!=0 and age<50 **/
$where=array(‘type’=>array(‘$exists’=>true)??’age’=>array(‘$ne’=>0??’$lt’=>50??’$exists’=>true));
$cursor = $collection->find($where);
//** ??????????? **/
$cursor = $collection->find()->limit(5)->skip(0);
//** ???? **/
$cursor = $collection->find()->sort(array(‘age’=>-1??’type’=>1)); ##1??????? -1??????????????????????????
//** ???? **/
$collection->ensureIndex(array(‘age’ => 1??’type’=>-1)); #1??????? -1???????
$collection->ensureIndex(array(‘age’ => 1??’type’=>-1)??array(‘background’=>true)); #???????????????????(????????????)
$collection->ensureIndex(array(‘age’ => 1??’type’=>-1)??array(‘unique’=>true)); #?????????
/**
* ensureIndex (array()??array(‘name’=>’????????’??'background’=true??’unique’=true))
* ???:http://www.php.net/manual/en/mongocollection.ensureindex.php
*/
//** ??ò????? **/
$cursor = $collection->find();
$array=array();
foreach ($cursor as $id => $value) {
$array[]=$value;
}
|