MongoDB change order of array in document
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
精彩评论