Chcete-li to provést atomicky, všechny vaše tři vzorové dokumenty musí být součástí stejného dokumentu. MongoDB provádí atomické operace pouze s jednoduchými dokumenty:http://www.mongodb.org/ display/DOCS/Atomic+Operations
Pokud jsou součástí jednoho dokumentu, změní se pořadí 2. a 3. vnořeného dokumentu takto:
> db.so.find().pretty();{ "_id" :ObjectId("4f55e7ba362e2f2a734c92f8"), "subs" :[ { "id_autora" :"a", "třída" :"princip", "content_id" :null, "host_id" :null, "modified_date" :1330935540, "order" :1, "pub_date" :1330935540, "score" :0, "text" :"Hello World_down_count", "vote":0, "vote_up_count" :0 }, { "author_id" :"a", "class" :"principle", "content_id" :null, "host_id" :null, "modified_date" :1330935538, "order" :2, "pub_date" :1330935538, "score" :0, "text" :"Rád vás poznávám.", "vote_down_count" :0, "vote_up_count" :0 }, { "author_id" :"a", "class" :"principle", "content_id" :null, "host_id" :null, "modified_date" :1330935548, "order" :3, "pub_date" :1330935548, "score" :0, "text" :"Skvělé!", "vote_down_count" :0, "vote_up_count" :0 } ]}
Dotaz:
db.so.update( { _id:new ObjectId("4f55e7ba362e2f2a734c92f8")}, { $set :{ 'subs.1.order' :3, 'subs.2.order' :2 } });Výsledek:
> db.so.find().pretty();{ "_id" :ObjectId("4f55e7ba362e2f2a734c92f8"), "subs" :[ { "id_autora" :"a", "třída" :"princip", "content_id" :null, "host_id" :null, "modified_date" :1330935540, "order" :1, "pub_date" :1330935540, "score" :0, "text" :"Hello World_down_count", "vote":0, "vote_up_count" :0 }, { "author_id" :"a", "class" :"principle", "content_id" :null, "host_id" :null, "modified_date" :1330935538, "order" :3, "pub_date" :1330935538, "score" :0, "text" :"Rád vás poznávám.", "vote_down_count" :0, "vote_up_count" :0 }, { "author_id" :"a", "class" :"principle", "content_id" :null, "host_id" :null, "modified_date" :1330935548, "order" :2, "pub_date" :1330935548, "score" :0, "text" :"Skvělé!", "vote_down_count" :0, "vote_up_count" :0 } ]}