I am wondering what is the best layout for a “customer service” document in MongoDB. I thought something like this, but not sure.
{
"userid":(MONGODBUSERID),
"subject":"subjectofissue",
"issue":"issue that the user has",
"replies":[{
"whoreplied":"staff/customer",
"uid":"userid of replier",
"msg":"msg of reply"
}]
}
Is that the best way to do it? If so how would I update the replies array with PHP? I need to insert into the replies array without overwriting past replies.
I tied this but got the following error
Fatal error: Uncaught exception ‘MongoException’ with message ‘zero-length keys are not allowed, did you use $ with double quotes?’ in /home/MYSITE/public_html/core.php:347
Stack trace:
my code
$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);
You need to surround the
$pushcommand on line 2 with single quotes (') instead of double quotes ('").Double quotes will cause PHP to treat
$pushas a variable and attempt to replace it with the variable’s value.