2016-08-02 40 views
2

我目前使用的是PouchDB,我正在利用Cloudant使PouchDB中的數據庫在雲上運行。PouchDB on Cloudant

我做了回調方法,它給了一個成功的回調,但是,我檢查我的Cloudant數據庫,有0個文件創建,但有8個更新序列。

我可以知道爲什麼嗎?這是我使用的一組代碼。

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); 

} 

結果我回來就是

Successfully posted a todo!

+0

也許'http:// example.cloudant.com/example'不是正確的數據庫鏈接。我認爲你必須鏈接在你的賬戶中創建的數據庫。 – Hydro

+0

@TheProHands在我的實際代碼中,我將其設置爲「http:// USERNAME.cloudant.com/DATABASE」,其中'USERNAME'是我的用戶名,'DATABASE'是我的數據庫的名稱。 – Alvin

+1

@TheProHands我已經解決了這個問題,我發佈了我自己的解決方案。非常感謝你的幫助!非常感謝! – Alvin

回答

2

解決方案:

我的錯誤是因爲我用的是主機鏈接是不正確的。它的格式應該是http://username:[email protected]。我生成了一個API密鑰,並將該密鑰用作用戶名和密碼作爲密碼。然後它工作。我能夠創建和查詢文檔。