Jacob
Jacob

Reputation: 1672

CouchDB combine sorted documents to one document

I have 2 documents:

  1. { path: "/monster/green", name: "Green monster", age: 105, timeline: 1 }

  2. { path: "/monster/green" name: "Really Green Monster", timeline: 2 }

The question:

How can I create a CouchDB view, where the documents are sorted by 'timeline' and the result is a combination of them:

{ path: "/monster/green", name: "Really Green Monster", age: 105 }

Upvotes: 1

Views: 63

Answers (1)

Aurélien Bénel
Aurélien Bénel

Reputation: 3842

You can easily create a view which will give you the following output for key="/monster/green" :

{[
  {"key":"/monster/green", "value":{"name": "Green monster", "age": 105},
  {"key":"/monster/green", "value":{"name": "Really Green monster"}
]}

Except the format, this is really similar to the data you wanted. If you really need to change the format, you can define a list on top of your view.

Upvotes: 1

Related Questions