database - NoSQL store re-orderable list of elements -
i have nosql setup follows:
userid : contentid : orderid user1 : content1 : 0 user1 : content2 : 1 user2 : content3 : 0 user2 : content4 : 1 user2 : content5 : 2 user2 : content6 : 3 user2 : content7 : 4 i list of user2 items sorted order
select * table userid = 'user2' sort orderid desc which results in
userid : contentid : orderid user2 : content3 : 0 user2 : content4 : 1 user2 : content5 : 2 user2 : content6 : 3 user2 : content7 : 4 great! want swap table looks this:
userid : contentid : orderid user2 : content3 : 0 user2 : content6 : 3 user2 : content4 : 1 user2 : content5 : 2 user2 : content7 : 4 so move content6 after content3 , before content4. drawback update orderid have update every row after content3 resulting in multiple writes datastore.
what better way of doing in nosql database?
you can solve more sophisticated algorithm, can create big gap between keys , move item 1 place inbetween other keys.
after while spaces may run out algorithm in case have normalize table , gaps between keys, resulting in 1 time procedure bit heavier on database. can done periodically or on demand when detect running/ran out of space example.
so original table like:
before
userid : contentid : orderid user2 : content3 : 0 user2 : content4 : 1000 user2 : content5 : 2000 user2 : content6 : 3000 user2 : content7 : 4000 after
userid : contentid : orderid user2 : content3 : 0 user2 : content6 : 500 user2 : content4 : 1000 user2 : content5 : 2000 user2 : content7 : 4000
Comments
Post a Comment