我在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
有人知道为什么吗?
我猜这是因为:
$result = $this->mongo->pages->update($condition1, array('$pull' => array('Pinned' => null)), array('safe' => true));
您的文档中没有Pinned
,而且它绝对不是一个数组。
这就是这个错误的本质:Pinned
不是一个数组。
您确实使用了单引号('')。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));