开发者

MongoDB change order of array in document

开发者 https://www.devze.com 2023-04-12 16:07 出处:网络
so here is my current data structure: [parents] => Array ( [0] => Array ( [title] => Test 1 ) [1] => Array (

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开发者_如何学JAVA ideas how to tackle this?


Just fetch data from mongo by natural order

$cursor = $p->find($range,$co)->sort(array('$natural' => -1) );


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

0

精彩评论

暂无评论...
验证码 换一张
取 消