sugar
sugar

Reputation: 251

replicate pouchDB document with couchDB

I have used pouchDB in one application and now I want to introduce couchDB to sync the document to remote server. Hence i followed this link http://pouchdb.com/getting-started.html i used the below code to replicate the data to couchDB

var db2 = new PouchDB('todos');
var remoteCouch = 'http://localhost:5984/_utils/database.html?couchdb_sample';

 db2.changes({
since: 'now',
live: true
}).on('change', showTodos);
sync();
function sync() {
 //alert("sync");
//syncDom.setAttribute('data-sync-state', 'syncing');
//var opts = {live: true};
db2.replicate.to(remoteCouch).on('complete', function () {
console.log("done");
}).on('error', function (err) {
    console.log(err);
});

function addTodo(text) {
var todo = {
_id: $("#eid").val()+$("#version").val(),
title: text,
name: $("#nameid").val(),
version: $("#version").val(),
completed: false
};
db2.put(todo, function callback(err, result) {
  if (!err) {
    console.log('Successfully posted a todo!');
  }
  else{
  console.log(err);
  }
 });}

here the title has an xml string as value. But i am facing below error

SyntaxError: Unexpected token <

    at Object.parse (native)

for this line db2.replicate.to(remoteCouch). I manually created a new document in couchDb database and entered the same data it gave no error but when i try replicating it shows syntax error. Can anyone please hint me where I have gone wrong

Upvotes: 0

Views: 431

Answers (2)

IanC
IanC

Reputation: 883

It look like you have not defined the remote database in the way PouchDb is expecting. You should use the "new PouchDb" call. The second line of your code is:

var remoteCouch = 'http://localhost:5984/_utils/database.html?couchdb_sample';

but I think it should be like this:

var remoteCouch = new PouchDB('http://localhost:5984/couchdb_sample');

I am not clear from your code what the name of the remote database is, but it would not normally end in ".html" as Ingo Radatz pointed out, so I have assumed it is couchdb_sample above. There is more information about replication on the PouchDb site.

Upvotes: 0

Ingo Radatz
Ingo Radatz

Reputation: 1225

http://localhost:5984/_utils/database.html?couchdb_sample

Points to a HTML site (copied over from the browsers address bar, right?). Remove the middle part:

http://localhost:5984/couchdb_sample

Upvotes: 1

Related Questions