background image

//** 

 

修改更新 **/

$where

=

array

(‘column_name'=>'col123′);

$newdata

=

array

(‘column_exp'=>'GGGGGGG','column_fid'=>444);

$result

=

$collection

->update(

$where

,

array

(‘

$set

'=>

$newdata

)); #

$set

:让某节点等于给定值,类似

的还有

$pull

 

$pullAll

 

$pop

 

$inc

,在后面慢慢说明用法

/*
* 结果:
* 原数据

{“_id”:ObjectId(“4d635ba2d549a02801000003″),”column_name”:”col123″,”column_exp”:”xiaoc
ai”}
* 被替换成了

{“_id”:ObjectId(“4d635ba2d549a02801000003″),”column_name”:”col123″,”column_exp”:”GGG
GGGG”,”column_fid”:444}
*/
//** 

 

替换更新 **/

$where

=

array

(‘column_name'=>'col709′);

$newdata

=

array

(‘column_exp'=>'HHHHHHHHH','column_fid'=>123);

$result

=

$collection

->update(

$where

,

$newdata

);

/*
* 结果:
* 原数据

{“_id”:ObjectId(“4d635ba2d549a02801000003″),”column_name”:”col709″,”column_exp”:”xiaoc
ai”}
* 被替换成了

{“_id”:ObjectId(“4d635ba2d549a02801000003″),”column_exp”:”HHHHHHHHH”,”column_fid”
:123}
*/
//** 

 

批量更新 **/

$where

=

array

(‘column_name'=>'col');

$newdata

=

array

(‘column_exp'=>'multiple','91u'=>684435);

$result

=

$collection

->update(

$where

,

array

(‘

$set

'=>$newdata),array(‘multiple'=>true));

/**
* 所有'column_name'='col'都被修改
*/
//** 

 

自动累加 **/

$where

=

array

('91u'=>684435);

$newdata

=

array

(‘column_exp'=>'edit');

$result

=

$collection

->update(

$where

,

array

(‘

$set

'=>$newdata,'

$inc

'=>array('91u'=>-5)));