using unset in CakePHP MongoDB -


i using ichikawa cakephp mongodb plugin. have problem in using unset in it. have tried command in shell:

 db.patents.update({}, {$unset : {"lv.2" : 1 }},{'multi':true})  db.patents.update({},{$pull:{pid:"2"}},{'multi':true}) 

these working fine.

but when converting them cakephp command follows:

 $this->detail->updateall(array('$unset'=>array('lv.2'=>1,array('multi'=>true)))); 

then doesn't work , gives error:

 mongocollection::update(): expects parameter 1 array or object, boolean given 

can me figure out problem.

thanks.

there no conditions

the error message means query being generated equivalent of:

db.details.update(true 

this can confirmed checking query log (easy if you're using debug kit).

how happening

the second parameter model updateall missing, means have default:

public function updateall($fields, $conditions = true) {                                                  ^     return $this->getdatasource()->update($this, $fields, null, $conditions); } 

therefore in mongodb datasource class - conditions passed true:

public function updateall(&$model, $fields = null,  $conditions = null) {                                                     ^ 

as consequence, resultant update statement has true first parameter, not array.

correct syntax

the correct syntax such query is:

$this->detail->updateall(     array('$unset'=>array('lv.2'=>1))     array() # <- not omit ); 

note it's not necessary specify 'multi'=>true the datasource you, not in fields argument.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -