Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用CakePHP在MongoDB子文档中保存数据_Cakephp_Mongodb_Cakephp 2.0 - Fatal编程技术网

使用CakePHP在MongoDB子文档中保存数据

使用CakePHP在MongoDB子文档中保存数据,cakephp,mongodb,cakephp-2.0,Cakephp,Mongodb,Cakephp 2.0,在CakePHP中,我试图将数据保存在如下子文档中: $mongo = $this->User->getDataSource(); $mongo->update($this->User, array( array( '_id' => $tweep['User']['_id'], 'Services._id' => $tweep['User']['Services']['_id'] ), array('Se

在CakePHP中,我试图将数据保存在如下子文档中:

$mongo = $this->User->getDataSource();
$mongo->update($this->User, array(
    array(
        '_id' => $tweep['User']['_id'],
        'Services._id' => $tweep['User']['Services']['_id']
    ),
    array('Services.$.following' => $following)
));
但很明显我做错了什么,因为它不起作用

$following是我想保存在带有特定id的服务下的数组

这是数据源方法:

使用updateAll()方法代替update()

使用MongoDbCollection对象。

我不熟悉php/cake语法,但是额外的封装
array()
似乎不正确,我发现这样做:$Users=$this->User->getMongoDb()->Users;这对我来说也很有效,尽管我花了一些时间才弄明白如何更新。我想知道是否有一种方法可以在不绕道db对象的情况下以蛋糕的方式实现这一点。无论如何,谢谢你的提示!