what is the best practice to sort/order multiple documents by user defined order (position) in CouchDB?
Solutions I thought about:
Every document has a "position" value, starting from 1 to n. The view would emit this value. Problem: If one document is sorted, all other documents with a greater position have to updates. This could be hundreds of updates. Hmm.
Every document knows it's previous document's _id. The order is generated after retrieving the view.
The is a special document storing the _ids of all documents that should be sorted in an array. We sort in this solution again after retrieving the view.
Is the any other or more simple solution? In a 开发者_如何学JAVARDBMS solution 1. was the best practice and a simple update query did the position update of all documents.
Best regards, Bernd
You could use a float value, for example between 0.0 and 1.0 for the position. To move Document A in between documents B and C then you just set its new position to (B.position + C.position) / 2.0
(i.e. the average of their positions).
精彩评论