1

我在 mongo 中有一个具有以下结构的表:

array(
    'Subscriber' => array(
         '0' => 'Name 1',
         '1' => 'Name 1',
         '2' => 'Name 2',
    )
)

我正在使用以下代码从订阅者中删除项目:

$setData["subscriber.1"]=1;
$result = $this->mongo->pages->update($condition1, array('$unset' => $setData), array('safe' => true));
$result = $this->mongo->pages->update($condition1, array('$pull' => array('subscriber' => null)), array('safe' => true)); 

它工作正常,但给出Mongo cursor Error:Cannot apply $pull/$pullAll modifier to non-array

有谁知道为什么?

4

2 回答 2

1

我猜是因为:

$result = $this->mongo->pages->update($condition1, array('$pull' => array('Pinned' => null)), array('safe' => true));

您的文档中没有Pinned,它绝对不是一个数组。

这基本上就是这个错误所说的:Pinned不是数组。

于 2013-02-18T08:28:48.190 回答
-1

您确实使用了单引号 ('')。PHP 将忽略单引号内的变量。您必须删除单引号或用双引号替换它们。

这应该有效:

$setData["subscriber.1"]=1;
$result = $this->mongo->pages->update($condition1, array($unset => $setData), array('safe' => true));
$result = $this->mongo->pages->update($condition1, array($pull => array('Pinned' => null)), array('safe' => true)); 
于 2013-02-18T08:26:12.640 回答