tags:

views:

43

answers:

1

Whenever a document is accessed, I would like to add last access time into the document. How do I update a document in views whenever there is GET request?

Thanks

+1  A: 

You can't. A GET (when used correctly) does not modify data; CouchDB uses GET correctly.

If you really want to record an access time like this you'll need to update the document with the new timestamp and PUT the document back to CouchDB. However, if more than a few people are accessing a document you're quite likely to get contention over it and get conflict errors from CouchDB.

One option is to create a new "document accessed" document in CouchDB on each access but that would rapidly increase the size of the database. You'd actually have a history of access times if that's useful?

Personally, I would look at simply logging document access to a file or queue and process the file/queue in the background. You could have one "document accessed" document per real document as there's little or no chance of contention and a failed update probably wouldn't really matter (you could always try again anyway).

Matt Goodall
You can also use an update function to update a field or fields without getting the whole document first. http://wiki.apache.org/couchdb/Document_Update_Handlers
duluthian