开发者

Adding last access time to CouchDB document in a view

Whenever a document is accessed, I would like to add last access time into the document.

How do I update a document in a view whenever there is GET requ开发者_运维技巧est?


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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜