2

I have this use case, where I have created server side views on sync gateway based on a rolling time window of 10 days. Is there a way to directly pull those on my device side?

When I look at the documentation, I see that there's no way these can be replicated directly and one needs to make REST calls:

http://developer.couchbase.com/documentation/mobile/1.2/develop/guides/sync-gateway/accessing-cb-views/index.html

Is that assumption correct?

The other approach I saw was that let all the data be replicated on the client side and then write Couchbase lite views on the client side using Map reduce functions. Which one's the correct approach out of the 2?

Sagar
  • 229
  • 4
  • 14

2 Answers2

0

Yes I believe that your assumption is correct - views have to be queried directly via the public REST API. I also believe that your solution for syncing data and then querying it on the client side will also work.

In order to find the "correct approach" I would consider your app needs and deployment workflow:

  • Using view on the server will require:
    • Managing (CRUD) of the views in SG - similar to managing functions in a database. These would ideally be managed by some deployment / management code.
    • Clients need to be able to make the API call to the public interface to access view info. This then requires a cache to work offline.
  • Slicing data locally means that sync will bring down all data and the device will have to perform the search / slice / aggregation previously carried out by the server. This will:
    • Work offline.
    • Put a potential extra strain on the app device.

I don't think that there are any easy answers here - ideally views would be synced to the device, but I don't know if that's even possible with the current SG implementation.

(Note 1: that the views must be created in Sync Gateway via the admin REST interface and not through the Couchbase web interface.).

(Note 2: I'm a server-side programmer, so this view is tainted.)

jamesc
  • 5,852
  • 3
  • 32
  • 42
0

What I ended up doing was writing webhooks, which basically let me have the same docs replicated onto a Couchbase server. Then I did all needed aggregations and pushed those to syn gatewy(which got replicated to the app).

May or mayn't be right but works for my case....

Sagar
  • 229
  • 4
  • 14