Error buffer when resolve conflicts in server

i have this architecture
couchbase server 4.5.1
couchbase lite 1.3.1
sync gateway 1.3.1
node js v6.11.0

i want resolve conflicts in my server i am following the documentation (https://developer.couchbase.com/documentation/mobile/current/guides/sync-gateway/resolving-conflicts/index.html) but the console throw the next error

buffer.js:495
throw new Error(’“toString()” failed’);
^

Error: “toString()” failed
at Buffer.toString (buffer.js:495:11)
at Request. (/home/ec2-user/node_modules/request/request.js:1145:39)
at emitOne (events.js:96:13)
at Request.emit (events.js:188:7)
at IncomingMessage. (/home/ec2-user/node_modules/request/request.js:1091:12)
at IncomingMessage.g (events.js:292:16)
at emitNone (events.js:91:20)
at IncomingMessage.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickCallback (internal/process/next_tick.js:104:9)

any idea how to solve this?-

This is being thrown by your node app. Not sure how to help you debug it without more information. Do you have a code snippet?

1 Like

thanks for reply :clap:

CODE:

getChanges(seq);

function getChanges(seq) {
var querystring = ‘style=all_docs&active_only=true&include_docs=true&only_conflicts=true&feed=longpoll&since=’ + seq;
var options = {
url: sync_gateway_url + ‘_changes?’ + querystring
};
// 1. GET request to _changes?feed=longpoll&…
request(options, function (error, response, body) {
if (!error && response.statusCode == 200) {
var json = JSON.parse(body);
for (var i = 0; i < json.results.length; i++) {
var row = json.results[i];
var changes = row.changes;
//console.log(“Document with ID " + row.id + " has " + changes.length + " revisions.”);
// 2. Detect a conflict.
if (changes.length > 1) {
console.log(“Conflicts exist. Resolving…”);
resolveConflicts(row.doc, function() {
getChanges(row.seq);
});
return;
}
}
// 3. There were no conflicts in this response, get the next change(s).
getChanges(json.last_seq);
}
});
}

this code is in link documentation (Couchbase Capella for Mobile Developers)

i resolved this.
the error throw because the json of sequence its to large i think its because i have many documents (3 millions)

i had to change de procesor of json

i use JSONStream lib and works very well for me
i share the link of lib