我有一个mongo文档,其结构与此类似:
foreach ($dogs as $dog) {
$dog['breed'] = array(
'id' = $dog['breed_id'],
'name' => $dog['breed_name']
);
unset($dog['breed_id']);
unset($dog['breed_name']);
}
return $dogs;
当消息发送到组或组成员的子集时,我需要将消息添加到消息的每个接收者的每个{
Group: "Some group",
Members: [
{ Name: "First Member", Messages: [] },
{ Name: "Second Member", Messages: [] }
]
}
数组中。
所以,假设我有以下要保存的消息列表:
Messages
我真的需要找到一种方法将这些消息添加到组文档中,而不替换文档,因为可能会同时发生多个更新。
我发现的最佳方式是更新语句列表和批量写入:
[
{ Receiver: "First Member", Message: { Subject: "subject", Text: "..."}},
{ Receiver: "Second Member", Message: { Subject: "subject", Text: "..."}},
{ Receiver: "Second Member", Message: { Subject: "whatever", Text: "..."}},
]
这是最好的方法吗?或者我还有其他方法可以尝试吗?