Miralem Cebic
Miralem Cebic

Reputation: 1301

CouchDB and iOS

I need some help with a CouchDB iOS project.

I'm using Apache CouchDB Server and the couchbase-lite iOS Framework.

On my CouchDB I have a template document.

 - CouchDB Server
   - database
     - template
     - document 1
     - document 2
     - ...

My goal is to only synchronise my iPad with this template document to get the latest data which my application needs. But when I enter some data on my iPad, I want that this data should be pushed only to couchBase Server.

How can I "tell" my application to synchronise only one file and not the entire database with my server and at the end how can I "tell" my application to only push the data that is input from user side ?

More importantly, Do I need two databases on my server? One for the template and a second one for user input data? If YES, then I just need to know how I can only push my data. Guidance needed. Thanks.

Upvotes: 1

Views: 1461

Answers (1)

Hans
Hans

Reputation: 2910

This is how I solve this:

  • I tend to add a 'last update' date to all my documents, and store this in a format that means they'll be sorted in time order (epoch or yyymmddhhmmss) both do.
  • Create a view that uses the update time as a date.
  • On your client, store the time since you last updated.
  • When you update, access the view with a startkey parameter set to the last update date.
  • You can then either use 'include-docs=true' to get the documents as you query the view.
  • I tend to use 'include-docs=false' though as it means when a lot of documents have been updated I transfer less data in a single query. I then just directly access each document id that the view returns.

Upvotes: 1

Related Questions