MongoDB 更改文档中数组的顺序
所以这是我当前的数据结构:
[parents] => Array (
[0] => Array (
[title] => Test 1
)
[1] => Array (
[title] => Test 2
)
)
我想在其开头添加一个新数组,因此 array[0] 将变为 array[1] (如下所示)
[parents] => Array (
[0] => Array (
[title] => Test 3
)
[1] => Array (
[title] => Test 1
)
[2] => Array (
[title] => Test 2
)
)
我需要一次更新多个文档,所以我不想要在循环内对每个文档单独运行更新命令。有什么想法如何解决这个问题吗?
so here is my current data structure:
[parents] => Array (
[0] => Array (
[title] => Test 1
)
[1] => Array (
[title] => Test 2
)
)
I want to add a new array to the BEGINNING of this, so array[0] would become array[1] (shown below)
[parents] => Array (
[0] => Array (
[title] => Test 3
)
[1] => Array (
[title] => Test 1
)
[2] => Array (
[title] => Test 2
)
)
I need to update multiple documents at once, so I don't want to individually run an update command on each document within a loop. Any ideas how to tackle this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需按自然顺序从 mongo 获取数据
Just fetch data from mongo by natural order
目前还不可能,因为服务器还不支持。请关注
https://jira.mongodb.org/browse/SERVER-2191
https://jira.mongodb.org/browse/SERVER-2036
It's not possible at the moment since the server doesn't support it yet. Please watch for
https://jira.mongodb.org/browse/SERVER-2191
https://jira.mongodb.org/browse/SERVER-2036