【发布时间】:2012-07-28 11:47:09
【问题描述】:
我想知道 MongoDB 中“客户服务”文档的最佳布局是什么。我想过这样的事情,但不确定。
{
"userid":(MONGODBUSERID),
"subject":"subjectofissue",
"issue":"issue that the user has",
"replies":[{
"whoreplied":"staff/customer",
"uid":"userid of replier",
"msg":"msg of reply"
}]
}
这是最好的方法吗?如果是这样,我将如何使用 PHP 更新回复数组?我需要插入回复数组而不覆盖过去的回复。
我绑定了这个,但出现以下错误
致命错误:未捕获的异常 'MongoException' 带有消息“不允许使用零长度的键,您是否使用带双引号的 $?”在 /home/MYSITE/public_html/core.php:347
堆栈跟踪:
我的代码
$array = array(
"$push" => array(
"replies" => array(
"whoreplied" => "user",
"uid" => new MongoId($this->data['uid']),
"msg" => $this->data['issue']
)
)
);
$collection->update(array(
"_id" => new MongoId($this->data['customerID'])
), $array);
【问题讨论】:
-
错误消息给了你正确的提示..你希望 '$push' 将它作为命令发送到 MongoDB 服务器,而不是 "$push" 它将评估 @ 的内容987654323@ 变量。