Couchbase Server and Sync Gateway (Error Unmarshaling doc)


#1

Hi guys, i am trying to follow the hello couchbase example. But i keep getting the wrong output. My server console on command prompt keep getting
*"2016-06-13T15:44:49.193+08:00 WARNING: changeCache: Error unmarshaling doc “21st_amendment_brewery_cafe-amendment_pale_ale”: – db.(changeCache).DocChanged.func1() at change_cache.go:327"

while executing the hello-couchbase.js file the output is
Amendment Pale Ale, ABV: 5.2
{ cas: CouchbaseCas<62246400317204>, token: undefined }

it is a different output from the 1 stated in the tutorial
http://developer.couchbase.com/documentation/server/4.1/sdks/node-2.0/hello-couchbase.html

Config.Json
{
“log”: [“REST”],
“adminInterface”: “127.0.0.1:4985”,
“interface”: “0.0.0.0:4984”,
“databases”: {
“db”: {
“server”: “http://localhost:8091”,
“bucket”:“beer-sample”,
“users”:{
“GUEST”: {“disabled”: false, “admin_channels”: ["*"] }
}
}
}
}

hello-couchbase.js
var couchbase = require(“couchbase”);

// Connect to Couchbase Server

var cluster = new couchbase.Cluster(‘127.0.0.1’);
var bucket = cluster.openBucket(‘beer-sample’, function(err) {
if (err) {
// Failed to make a connection to the Couchbase cluster.
throw err;
}

// Retrieve a document

bucket.get(‘21st_amendment_brewery_cafe-amendment_pale_ale’, function(err, result) {
if (err) {
// Failed to retrieve key
throw err;
}

var doc = result.value;

console.log(doc.name + ', ABV: ' + doc.abv);

// Store a document

doc.comment = "Random beer from Norway";

bucket.replace('21st_amendment_brewery_cafe-amendment_pale_ale', doc, function(err, result) {
  if (err) {
    // Failed to replace key
    throw err;
  }

  console.log(result);

  // Success!
  process.exit(0);
});

});
});


#2

That’s the expected Sync Gateway warning for documents that don’t have the sync metadata required by Sync Gateway.

Documents that are written directly via the Couchbase SDK don’t have the required metadata, and can’t be replicated to mobile devices with Sync Gateway. If you want your documents to be mobile aware, they should be written to the bucket through the Sync Gateway REST API.


#3

Hey, thanks for responding. Is this the Rest Api you are talking about ? http://developer.couchbase.com/documentation/mobile/current/develop/references/couchbase-lite/rest-api/index.html


#4

That’s the Couchbase Lite REST API. SG REST API docs are here:
http://developer.couchbase.com/documentation/mobile/1.2/develop/references/sync-gateway/index.html


#5

ohhh i see, which one should i use? i am want to transfer my documents from my android phone in couchbase lite to the couch base server.

And do you have any working examples?


#6

If you want to operate on documents on the Sync Gateway, from a server-side process, use the SG REST API.

If you have a mobile app written in JavaScript in a PhoneGap/Cordova/ReactNative container, use the Couchbase Lite REST API.

The two APIs are very similar as they both derive from the CouchDB API.

Yes, we have sample code posted on the website.


#7

For the SG REST API,is GrocerySync an exmaple of that ?


#8

No. Grocery Sync is a mobile app, so it uses the Couchbase Lite REST API.


#9

ohhh, so that means if i need to use couchbase lite rest api because i am using my mobile phone to transfer data from couchbase lite to the couchbase server, Am i right '?


#10

Your mobile application talks only to Couchbase Lite, using either the REST API (if it’s a JS app using PhoneGap or React Native), or the native APIs.

Couchbase Lite’s built-in replicator talks to Sync Gateway to sync data. You don’t have to worry about that or know how it’s done.

The only reason to use Sync Gateway’s REST API is if you are writing a server-side component (like an app server) that wants to view or modify documents in the database being managed by Sync Gateway.


#11

okayyyyy thank you !!