【发布时间】:2014-11-06 01:22:52
【问题描述】:
考虑以下文档:
{
"comments": [
{
"id" : 1,
"userid": "john",
"comment": "lorem ipsum...",
"responses": [
{
"id" : 2,
"userid": "smith",
"comment": "lorem ipsum...",
"responses": [
{
"id" : 3,
"userid": "random",
"comment": "lorem ipsum...",
"responses": [] // I want to push a comment into this array
},
{
"id" : 4,
"userid": "guy",
"comment": "lorem ipsum..."
}
]
},
{
"id" : 5,
"userid": "adam",
"comment": "lorem ipsum..."
}
]
}
]
}
有没有办法将文档推送到 responses 数组中?因此,在这种情况下,用户想要对 3 级评论发表评论,而我想将该评论推送到数组中。我可以在评论时将数组位置发送给用户并返回给服务器,但我很确定这是不可靠的。此外,如果在这两者之间发生删除(我猜(?)),数组中的位置会发生变化,所以这真的是不行的。
【问题讨论】:
-
每当我需要更新/编辑文档时,我都会使用 Robomongo。它快速简单
-
这并不能真正解决我的问题。
-
是否需要通过写命令来更新文档?
-
我需要在 Go 的后端自动更新文档。
-
所有 cmets 是否都有全局唯一 ID,无论它们位于嵌套级别的哪个位置?
标签: mongodb