Updating document in CouchBase Server via sync-gateway

375 views
Skip to first unread message

Michael Mayer

unread,
May 14, 2014, 12:24:58 PM5/14/14
to mobile-c...@googlegroups.com
I am writing an iOS application using CouchBase-Lite that will sync back to a Couchbase Server via the sync gateway.  I may also need the ability to read/update/create documents from another application, like a web application.  Based on this limitation
 
It cannot operate on pre-existing Couchbase buckets with app data in them because Sync Gateway has its own document schema and needs to create and manage documents itself. You can migrate existing data by creating a new bucket for the gateway and then using the Sync REST API to move your documents into it via PUT requests. You can’t make changes to the Couchbase bucket directly. You have to go through the Sync Gateway API
 
I am trying to understand how to insert and update documents via the Sync-Gateway REST API.  The insert seems pretty straight forward using the PUT /db/docid method but I'm not understanding the update scenario.  I have tried POST'ing to /db/_bulk_docs but I clearly do not understand the body structure the API is expecting as I receive an error that "interface is nil" in the sync gateway.
 
I guess my first question is, is the approach I am pursuing the correct approach.  And second, how should I format my POST to update existing documents via the Sync-Gateway.
 
Thank You
Mike Mayer

Jens Alfke

unread,
May 14, 2014, 1:28:53 PM5/14/14
to mobile-c...@googlegroups.com

On May 14, 2014, at 9:24 AM, Michael Mayer <mi...@themayerhouse.com> wrote:

> I am trying to understand how to insert and update documents via the Sync-Gateway REST API. The insert seems pretty straight forward using the PUT /db/docid method but I'm not understanding the update scenario.

Update is just another PUT, but you have to include the document’s current revision ID as the body’s “_rev” property. (This is to prevent multiple writers from clobbering each others’ writes.) The revision ID is returned from the PUT call, and also appears as “_rev” in a GET.

> I have tried POST'ing to /db/_bulk_docs but I clearly do not understand the body structure the API is expecting as I receive an error that "interface is nil" in the sync gateway.

It’s expecting a MIME multipart body. You probably don’t need to use _bulk_docs, as it’s just an optimization vs issuing multiple PUT requests.

—Jens

Reply all
Reply to author
Forward
0 new messages