Re: Using Node.js SDK and/or Sync Gateway Rest APIs

I just wanted to clarify. I recently started working for a company that is using couchbase to develp the following:

REST APIS: Couchbase Server + Node.js + N1QL
MOBILE APP: Couchbase Mobile + Android SDK

I am refactoring the API portion and noticed that the initial developer manipulates objects using the Node.js Sdk and through the Syncgateway Admin REST APIs. For example to delete a user, we are deleting using bucket.remove and also deleting the user using the Admin REST API user endpoint.

For me, I thought it was duplication of the same task twice. The argument is that if I delete or the user using the node.js SDK in the API those changes will not translate to the mobile app that uses Syncgateway.

Any advice.

Currently mobile sync (Sync Gateway and Couchbase Lite) need extra meta-data to handle conflicts and replication that aren’t needed normally in Couchbase Server.

There are two ways to address this. One is using something we call “bucket shadowing”. This involves having a “normal” Couchbase Server bucket and a “shadow bucket” used by mobile. The buckets sync data between each other. You should see if the app was built this way. It may explain why you have the two approaches to deleting a user.

The preferred approach now is to run all data modifications through Sync Gateway. You can treat the Couchbase Server bucket as a read only source for querying, but you don’t want to modify the CB Server bucket directly in this approach.

I am pretty sure we haven’t started using “bucket shadowing”. I will use the preferred approach. Thanks for explaining in depth. :smile:

In summary:
GET -> CB Server directly
POST, PUT, DELETE - Sync Gateway endpoints (no need to double up and repeat using CB Server.)

Muchos gracias again,
Kris

1 Like