开发者

Save data in MongoDB subdocument with CakePHP

开发者 https://www.devze.com 2023-03-18 01:17 出处:网络
In CakePHP I am trying to save data in a subdocument like this: $mongo = $this-&g开发者_开发问答t;User->getDataSource();

In CakePHP I am trying to save data in a subdocument like this:

$mongo = $this-&g开发者_开发问答t;User->getDataSource();
$mongo->update($this->User, array(
    array(
        '_id' => $tweep['User']['_id'],
        'Services._id' => $tweep['User']['Services']['_id']
    ),
    array('Services.$.following' => $following)
));

But obviously I am doing something wrong as it doesn't work.

$following is an array that I would like to save under Services whith a specific id.

This is the datasource method: https://github.com/ichikaway/cakephp-mongodb/blob/cake2.0/Model/Datasource/MongodbSource.php#L635


use updateAll() method instead of update().

or

use MongoDbCollection Object. https://github.com/ichikaway/cakephp-mongodb/wiki/How-to-get-MongoObject-or-MongoCollection-object

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号