I’m new to the couchbase world so this question might be silly. Is there a way to use the SDK to connect to sync gateway not the couchbase db directly?
I’m creating web application (Java) for managing some aspects of my product, and I want to work with documents that are used in synchronization on mobile devices (couchbase-lite). The documentation says when my web app works with couchbase db server, changes are not applied on sync gateway. So can the SDK work with sync gateway as well, or should I use public rest API (https://developer.couchbase.com/documentation/mobile/1.4/references/sync-gateway/rest-api/index.html) for working with documents on the sync gateway?
you should work with sync gateway public rest api.
Couchbase recently released Couchbase Server 5.0 beta and Sync Gateway 1.5 beta. With this release, and you can use either the Sync Gateway REST API or the Java SDK to access and change documents in Couchbase Server.
In previous versions of Couchbase Server and Sync Gateway, if you are working with documents being synchronized via the Sync Gateway, you should change them only via the Sync Gateway REST API.
How can we add in a synced way? I just use upsert method, the document was added but its wasn’t seem that synchronized. When I get a session id and call all_docs, it returned empty. Moreover, in bucket, there wasn’t “_sync:” keyword appended. Should I use a different method?
Note: I’m using both beta versions and want to add via Java SDK instead of make a api call to gateway.
Thanks.
OK, Assuming that you have moved to Sync Gateway 1.5 / Couchbase Server 5.0 (beta), a quick note that the sync metadata has been moved out of the _sync property in the document into Extended Attributes XATTRs.
That said, I take it that you do not see any documents with _sync
prefix in the bucket ? That would imply that the sync did not happen.
Couple of things to check -
- Can you confirm that your Sync Gateway import settings are configured correctly in the Sync Gateway config file as discussed here.
- If you haven’t done so already, can you enable [verbose logging] (https://developer.couchbase.com/documentation/mobile/1.4/guides/sync-gateway/config-properties/index.html#server) on the Sync Gateway and restart the Sync Gateway. We can tell from the Sync Gateway logs if it is importing the documents correctly or not. If it imports correctly, you should see logs in the similar to these -
2017-06-15T14:17:00.283-04:00 Import: Created new rev ID 9-36ac54ab1140e178a01899d1825df183 2017-06-15T14:17:00.283-04:00 CRUD+: Invoking sync on doc "user::demo" rev 9-36ac54ab1140e178a01899d1825df183 2017-06-15T14:17:00.336-04:00 CRUD+: Saving old revision "user::demo" / "8-2e00f4e0211d6905382e027a64cd54ca" (1015 bytes) 2017-06-15T14:17:00.336-04:00 CRUD+: Backed up obsolete rev "user::demo"/"8-2e00f4e0211d6905382e027a64cd54ca" 2017-06-15T14:17:00.338-04:00 CRUD+: SAVING #31603 2017-06-15T14:17:00.338-04:00 CRUD: Stored doc "user::demo" / "9-36ac54ab1140e178a01899d1825df183" 2017-06-15T14:17:00.338-04:00 Import+: Imported user::demo (delete=false) as rev 9-36ac54ab1140e178a01899d1825df183 2017-06-15T14:17:00.339-04:00 Cache: Received #31603 after 1ms ("user::demo" / "9-36ac54ab1140e178a01899d1825df183")
…
Hi Priya,
I forgot to add the following lines to my sync gateway config json.
"unsupported": {
"enable_extended_attributes": true
},
"import_docs": "continuous"
Now I can fetch data smoothly. Thanks for your help.