Last active
January 9, 2016 15:03
-
-
Save craftzdog/ea55c8a1c835130e8974 to your computer and use it in GitHub Desktop.
PouchDB sync issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var PouchDB = require('pouchdb'); | |
var local = new PouchDB('./db'); | |
function createDB () { | |
var promise = Promise.resolve(); | |
var docs = []; | |
for (var i=0; i<100; i++) { | |
docs.push({ | |
_id: 'note/' + i, | |
data: i | |
}); | |
} | |
docs.forEach(function (doc) { | |
promise = promise.then(function () { | |
return local.put(doc); | |
}) | |
.then((result) => { | |
doc._rev = result.rev; | |
doc.revision = 2; | |
return local.put(doc); | |
}); | |
}); | |
promise.then(function () { | |
console.log('saved'); | |
}); | |
} | |
createDB(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var PouchDB = require('pouchdb'); | |
var util = require('util'); | |
PouchDB.plugin(require('pouchdb-find')); | |
var local = new PouchDB('./db'); | |
function syncDB () { | |
var remote = new PouchDB('http://localhost:5984/note'); | |
local.sync(remote, { | |
//live: true, | |
//retry: true | |
}).on('complete', function (status) { | |
local.find({ | |
selector: { | |
_id: { $gte: 'note/', $lte: 'note/\uffff' } | |
} | |
}).then(function (result) { | |
console.info('notes:', result.docs.length); | |
}); | |
}).on('error', function (err) { | |
// boo, something went wrong! | |
console.error('replication failed:', util.inspect(err, { showHidden: true, depth: null, colors: true })); | |
}); | |
} | |
syncDB(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Steps to reproduce: