views:

237

answers:

2
I'm trying to write a couchdb view that takes a created_at timestamp in a sortable format (2009/05/07 21:40:17 +0000) and returns all documents that have a greater created_at value.

I'm specifically using couch_foo but if I can figure out how to write the view I can create it in futon or in the couch_foo model instead of letting couch_foo do it for me.

I've searched all around and can't figure out the map/reduce to do this, if it's possible.
+1  A: 

You want to write a view that creates a key of the timestamp field in that format, then query it with the startkey parameter.

So the view would look something like:

"map" : "function(doc) { emit(doc.timestamp_field, doc) }"

And your URL would be something like:

http://mysever/database/_design/mydoc/_view/myview?startkey="2009/05/07 21:40:17 +0000"

The HTTP view API page on the Wiki has more info. You may also consider the User Mailing List.

Evan
A: 

Please mind that couchdb works only on json values. If the timezone if the document stored in couchdb is different to the timezone of your startkey the query likely will fail.

ordnungswidrig