Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
829 views
in Technique[技术] by (71.8m points)

couchdb - Using Date() in views

Is it ever ok to use Date() in a CouchDB view to filter results based on the current date? I'm thinking it will only update the view if the record is changed?

If that's the case, is there a way of telling a view to reindex every 24 hours?

I realise I could pull all the data out in the view, and then use code to filter, but I'm wondering if there's a way of doing it all in the view.

question from:https://stackoverflow.com/questions/65942168/using-date-in-views

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Is it ever ok to use Date() in a CouchDB view to filter results based on the current date?

The Date() will be computed only during view rebuild so you can not use it to get a query result based on the query time.

I'm thinking it will only update the view if the record is changed?

The view is updated incrementally when docs are changed and it is completely rebuilt when its definition changes.

If that's the case, is there a way of telling a view to reindex every 24 hours?

No

I realise I could pull all the data out in the view, and then use code to filter, but I'm wondering if there's a way of doing it all in the view.

As an alternative you may use filter functions to filter the change feed. These filters are evaluated at query time so you may achieve your purpose with this functionality. Also, selectors may help on this.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...