Closed h1771t closed 3 years ago
Replication and views are distinct features of cloudant/couchdb. It is not possible to replicate using a view. You can achieve a similar effect using replication with a filter function or selector.
See last bullet point here: https://pouchdb.com/api.html#filtered-replication
How would I pull replicate a design doc with a view, where for eg: design doc id is: "_id": "_design/filterByTimestamp", and view function is: "views": { "now-minus-one-month": { "map": "function (doc)...
What syntax would I use for filter function or selector to query such? Thanks in advance.
This seems to work, thanks so much for your suggestion.
val filter = PullFilter("_view", mapOf("view" to "filterByTimestamp/now-minus-one-month")) val replicator = ReplicatorBuilder.pull().from(uri).to(ds).filter(filter).build()
hm be careful there. replication is not using the view index, it's just re-running the map function and letting docs through that would emit a row. It's better to write a filter function (https://docs.couchdb.org/en/stable/ddocs/ddocs.html?highlight=filter#filter-functions) or a selector (https://docs.couchdb.org/en/stable/api/database/find.html#find-selectors). A selector would be faster too.
A view called "now-minus-one-month" also makes me think you've made a mistake in your map function. If you are comparing a document property to the current date (i.e, new Date()
) then you have made a mistake. The map function in your view is called at indexing time not querying time, so it will return the wrong answers.
Bug Description
Cannot do a pull replication using views. As per: https://cloud.ibm.com/docs/Cloudant?topic=Cloudant-using-views
Using PullFilter to try get data from a view in a design doc, does not work. It appears that views must have a specific url format which seems to not be supported by this lib yet?
1. Steps to reproduce and the simplest code sample possible to demonstrate the issue
Cannot see code to be able to do a pull replication using view
2. What you expected to happen
I expect to be able do a pull replication using views.
3. What actually happened
Nothing.
Environment details