我想知道什麼是MongoDB中「客戶服務」文檔的最佳佈局。我想過這樣的事情,但不確定。建議的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」,它將評估$ push變量的內容。 – Stennie 2012-07-28 22:53:20