i have collection documents have index property indicating order , group property:
{ "item": "a1", "group": "a", "index": 1 } { "item": "a2", "group": "a", "index": 2 } { "item": "b1", "group": "b", "index": 3 } { "item": "b2", "group": "b", "index": 4 } { "item": "c1", "group": "c", "index": 5 } { "item": "c2", "group": "c", "index": 6 }
now want assign new index values based on ordering of groups: e.g. [b,c,a] should result in:
{ "item": "b1", "group": "b", "index": 1 } { "item": "b2", "group": "b", "index": 2 } { "item": "c1", "group": "c", "index": 3 } { "item": "c2", "group": "c", "index": 4 } { "item": "a1", "group": "a", "index": 5 } { "item": "a2", "group": "a", "index": 6 }
is there way in 1 update statement or have run query each document seperately? important initial ordering within group not changed.
Comments
Post a Comment