????5.??????????

 

//** ?????? **/
$where=array(‘column_name’=>’col685′);
$result=$collection->update($where??array(‘$unset’=>’column_exp’));
/**
* ??????column_exp
*/
/*
* *
* ???????:update(array $criteria?? array $newobj [?? array $options = array()  ] )
*       ???:1.????????滻????????????
*    2.????????????????? array(’91u’=>’684435′)??array(’91u’=>684435)
* *
*/
//** ???? **/
$collection->remove(); #??????
//** ??????MongoId **/
$id = new MongoId(“4d638ea1d549a02801000011″);
$collection->remove(array(‘_id’=>(object)$id));

????6.?????????

 

//** ???????? **/
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;
}