开发者

CouchDB - Sorting documents by position

what is the best practice to sort/order multiple documents by user defined order (position) in CouchDB?

Solutions I thought about:

  1. 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.

  2. Every document knows it's previous document's _id. The order is generated after retrieving the view.

  3. 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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜