Search code examples
node.jscouchbasecouchbase-litecouchbase-sync-gatewaycouchbase-ottoman

Couchbase Lite - synchronising reference fields


How does Couchbase Lite treat the Ottoman's ref fields when synchronising with Couchbase Server using Sync Gateway?

Trying to get myself familiar with Couchbase and after watching and reading about Couchbase Server & Couchbase Lite combination (This video, this tutorial, and official docs) I'm not understanding how Lite reflects the data models defined within the Server.

From what I see, Lite and Server are not much alike, even though both represent NoSQL databases. You define, store and work with data in - it seems - different ways. Nonetheless, the Sync Gateway is there to allow synchronising Lite with Server.

And here comes the main question - how do ref fields defined in Ottoman-based server (check Model References here) get reflected in Lite when synchronised using Sync Gateway?

Please correct me if I'm just getting the concept of refs or syncing completely wrong.


Solution

  • The document models of Couchbase Server and Couchbase Mobile are very similar. The main difference is that Couchbase Mobile reserves "_"-prefixed fields as metadata. Other than that, they both provide JSON documents named by string keys.

    I don't know anything about Ottoman, but it sounds like 'ref' fields just contain a string that's the ID of the destination document. That works the same on both.

    The thing I do know is that Ottoman uses a field name called _type in documents, which makes it incompatible with Couchbase Mobile. Sync Gateway will reject documents that contain properties prefixed with an underscore. I don't know if there's a way to tell Ottoman to use a different property name.