With the release of Couchbase Mobile 1.5 and Couchbase Server 5.0,mobile ,web and desktop apps can seamlessly access documents in the same Couchbase Server bucket.
This implies that a document created on the server via the Couchbase SDK will be automatically replicated to the mobile clients through the Sync Gateway and vice versa.
Note:This is an updated repost of the original version of this post
Background
Prior to Couchbase Mobile 1.5, if you wanted to replicate changes made to the server via the Couchbase SDK over to the mobile clients, your options were to :
- Enable Bucket Shadowing. (Note that Bucket shadowing is deprecated in Couchbase Mobile 1.4).
- Have your web app route the documents through the Sync Gateway using the REST interface.
Now, new in Couchbase Mobile 1.5, the sync metadata is part of the documentâs Extended Attributes or XAttrs and is no longer embedded within the document. Additionally, the Sync Gateway can be configured to automatically import documents added to the server via the SDK and associate it with the relevant sync metadata.
Enabling Unified Bucket Access
Enabling shared bucket access is simple. You will have to specify a couple of new configuration options in Sync Gateway Config file
– enable_shared_bucket_access
to true
: This enables Sync Gateway to use XAttrs
– import_docs
to continuous
: This causes the Sync Gateway to automatically import documents added via the SDK
Deployment Note: In a non-accel SG deployment, only a single SG node should have import_docs=continuous to avoid duplicate processing of documents
1 2 3 4 5 6 7 8 9 10 11 12 |
{ "interface":":4984", "log": ["*"], "databases": { "my_db": { "import_docs": "continuous", "bucket":"my_db", "server": "http://localhost:8091", "enable_shared_bucket_access":true  } } } |
Accessing the Sync Metadata
You can query for the XAttr via the Sync Gatewayâs _raw Admin REST API.
1 2 3 4 |
curl -X GET http://localhost:4985/my_db/_raw/my_doc \ -H 'accept: application/json' \ -H 'cache-control: no-cache' \ -H 'content-type: application/json' |
Currently, there is no way to query for the document sync metadata via the serverâs N1QL interface
Demo
Here is a video recording of a demo that showcases the power of unified bucket access from web and mobile clients.-
Questions?
If you have other questions or feedback, please leave a comment below or feel free to reach out to me at Twitter @rajagp or email me priya.rajagopal@couchbase.com.  The Couchbase Forums are another good place to reach out with questions.