问题
I am currently using PouchDB and I am making use of Cloudant to make my db in PouchDB to be on cloud.
I did callback method and it gave a success callback, however, I check my database on Cloudant, there's 0 doc created but there's 8 update seq.
May I know why? This is my set of code I used.
function pouchdb() {
var db = new PouchDB("todos");
var remoteDB = new PouchDB("http://example.cloudant.com/example");
var todo = {
_id: "mittens1233",
title: "hello",
occupation: "kitten123"
};
db.put(todo, function callback(err, result) {
if (!err)
console.log('Successfully posted a todo!');
});
db.put(doc);
PouchDB.sync(db, remoteDB);
}
The result i got back is
Successfully posted a todo!
回答1:
Solution:
My error was because the host link I was using was incorrect. It should be in a format of http://username:password@mycluster.cloudant.com . I generated an API key and used the key as username and password as password. Then it worked. I was able to create and query document.
来源:https://stackoverflow.com/questions/38725473/pouchdb-on-cloudant