couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Anderson <>
Subject Re: sorted documents by their position
Date Thu, 06 Aug 2009 15:53:35 GMT
On Thu, Aug 6, 2009 at 6:21 AM, didier
lafforgue<> wrote:
> hi all,
> I'm having fun time with couchdb but I'm stuck with a simple problem:
> documents sorted by their position. Actually, I've documents called projects
> described like this:
> {
>  _id: "first_project",
>   name: "my first project",
>   description: "lorem ipsum ...",
>   type: "project"
> }
> {
>  _id: "second_project",
>   name: "my second project",
>   description: "lorem ipsum ...",
>   type: "project"
> }
> And I'd like to sort them using a drag&drop ui. So, I thought about adding a
> new field (named position) and then updating their position field once I
> dragged one of them. You get the picture.
> Unfortunately, partial updates do not seem to exist in couchdb and I do not
> like the fact to save ALL my documents to update their positions, especially
> when I have hundred or thousand of projects.

If you store the position as a float (or a string) then you only have
to update the position on the changed document, not all of the docs in
the list.

Eg, if you want project P to come between projects B and C, then
average the positions of B and C and make that the new position of P.

> I came with an idea: denormalize the position field and create a document
> storing the positions (just an array field with project ids) so that I do
> not have to update all my documents but just the positions document. My only
> concern is that I'm unable to sort my projects with a couchdb view (I've to
> do it in the server side which is dirty).
> Is there a clean way to solve my problem ?
> Thanks guys !
>  Didier

Chris Anderson

View raw message