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
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
true: This enables Sync Gateway to use XAttrs
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
Accessing the Sync Metadata
You can query for the XAttr via the Sync Gateway’s _raw Admin REST API.
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
Here is a video recording of a demo that showcases the power of unified bucket access from web and mobile clients.-
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 firstname.lastname@example.org. The Couchbase Forums are another good place to reach out with questions.