我在 MongoDB 中有一个名为 topic 的集合
topic{
topic_title: 'thread',
reply{
reply_title: 'thread',
reply_content: 'content'
reply_created: "2013-06-18 17:54:04"
}
}
我想添加对该主题的回复,例如:
topic{
topic_title: 'thread',
reply{
reply_title: 'thread',
reply_content: 'content'
reply_created: "2013-06-18 17:54:04"
}
{
reply_title: 'reply1',
reply_content: 'reply2'
reply_created: "2013-06-18 17:57:04"
}
}
我的代码是这样的:
$reply = array(
"reply_title" => $title,
"reply_content" =>$content,
"reply_created" => date('Y-m-d H:i:s')
);
$document = array('$push' => array("reply" => $reply));
$id = new MongoId($topicid);
$topic->update(array("_id"=>$id),$document);
它做了这样的事情
topic{
topic_title: 'replytitle'
reply {
reply_title: "replytitle"
reply_content: "replycontent"
reply_created: "2013-06-18 17:57:12"
}
}
reply{
reply{
reply_title: "replytitle"
reply_content: "replycontent"
reply_created: "2013-06-18 17:57:12"
}
reply{
reply_title: "replytitle"
reply_content: "replycontent"
reply_created: "2013-06-18 17:57:12"
}
}
我真的很难做一件简单的事情。这是向回复数组添加回复。有什么帮助吗?