Reputation: 2910
I have the following problem:
I am storing URLs in a Couchdb with some additional information such as the release date. I have a view that returns all URLs where the published date is less than 12 hours old.
The odd thing is, that I am surprised that it works. Ie. after 24 hours of not touching the database, when the last action was to run the 'depreciating' view and returned some URLs, the next time this is called it does not return any items.
I assumed to have read, that a view is not running over all elements but only those that have changed or were added since the last time the view was run. This is why running a view a second time is usually faster than the first time.
In my example where documents 'expire' from the view, I would not have expect this to happen if there are no edits taking place.
Where am I going wrong?
Upvotes: 0
Views: 90
Reputation: 3852
Please, be sure that your view implementation does not depend of data outside the document (like the current date)... Or the cache mechanism implemented in CouchDB will be totally broken.
To get the URLs published less than 12 hours old, you must:
generate an index of the date of publishing (with date
being sortable, like [2013,10,22,13,54]
):
function(o) {
emit(o.date, null);
}
query the index from the most ancient time you want:
GET /mydb/_design/myapp/myview?startkey=[2013,10,22,1,56]&include_docs=true
Upvotes: 2