I wish to produce a database (I am using mongodb) collection which has a specific order which may also be changed. For instance, basically have

[A,B,C,D,E]

I possibly could move E towards the third position, and also the order could be

[A,B,E,C,D]

I must change as couple of objects as you possibly can, so putting a catalog on each object wouldn't work (since I'd have to change all subsequent elements' indexes for any simple move).

I possibly could also produce the objects just like a linked list, so each object might have the id from the previous and then objects. The example change would go such as this.

["A":{prev:null, next:"B"},
"B":{prev:"A", next:"C"},
"C":{prev:"B", next:"D"},
"D":{prev:"C", next:"E"},
"E":{prev:"D", next:null}]

would switch to

["A":{prev:null, next:"B"},
"B":{prev:"A", next:"E"},
"C":{prev:"E", next:"D"},
"D":{prev:"C", next:null},
"E":{prev:"B", next:"C"}]

This changes for the most part 5 objects for just about any size collection. A big change could be expressed as you up-to-date object, with a few logic to determine the other objects have to be up-to-date. This really is possible, but I'm wondering if there is an easy method than this even. Can there be an simpler method to keep an eye on an order of the arbitrary list?