Php 建议的MongoDB文档结构
我想知道MongoDB中“客户服务”文档的最佳布局是什么。我是这样想的,但不确定Php 建议的MongoDB文档结构,php,json,mongodb,Php,Json,Mongodb,我想知道MongoDB中“客户服务”文档的最佳布局是什么。我是这样想的,但不确定 { "userid":(MONGODBUSERID), "subject":"subjectofissue", "issue":"issue that the user has", "replies":[{ "whoreplied":"staff/customer", "uid":"userid of replier", "msg":"msg of reply" }] } 这是最好的方法吗?如果
{
"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);
第2行的
$push
命令需要用单引号('
)而不是双引号('”
)括起来
双引号将导致PHP将
$push
视为变量,并尝试用变量的值替换它。错误消息给出了正确的提示。您希望“$push”将其作为命令发送到MongoDB服务器,而不是“$push”,后者将根据$push
变量的内容进行计算。
$array = array(
'$push' => array(
"replies" => array(
"whoreplied" => "user",
"uid" => new MongoId($this->data['uid']),
"msg" => $this->data['issue']
)
)
);