SyncGateway working with WebApp

Provided I have a config for mobile syncing:

[Mobile Devs iOS/Android] <-> [Reverse Proxy] <-> [Sync Gateway] <-> [CouchBase Server]

And I want to create an Asp.Net WebApp that will read/write user data, how do I do it?

As far as I can tell - and I could be totally wrong - the Sync Gateway adds metadata to docs for syncing? Does that mean that if I wanted to read/write from the WebApp I would have to go through the Sync Gateway or could I directly access the CouchBase Server?

Is this possible at all and if so and what’s the best way of doing it?

Thank you

You can use the Sync Gateway REST API from your web-app.

You can also access the Couchbase Server bucket, as long as you play by the rules:

  1. Only read, never write.
  2. Ignore the "_sync" properties in documents, which contain internal Sync Gateway metadata.
  3. Ignore any keys in the bucket that start with _sync:.

If you define any views or N1QL queries, you’ll need to make them follow rules 2 and 3

In the long term we’re actively working on converging the storage systems so that these restrictions won’t be necessary — SG’s metadata will be invisible to you, and you’ll be able to modify documents without messing it up. It’s too early to announce anything about that, though.

1 Like

Thanks for the quick reply Jens.

I suppose it would be valid for the WebApp to do the reads via the Couchbase Server and writes via the Sync Gateway? That would probably be easier if my thinking is right.

Thank you!

If you write a doc to SG you need to have read it from SG — its MVCC enforces a “read, modify, write” pattern. That is, when you write you have to include the revisionID of the revision you read.

But if you’re not planning on writing back the document, you can read it from the bucket directly.

Yes makes sense - Thanks a lot!