如何指向源URL CouchDB中复制?

问题描述 投票:0回答:1

我有一个本地PouchDB必须与远程CouchDB的同步。我试图(但至今没有成功)复制一个本地(在localhost:8081)到远程一个(在localhost:5984)通过POST调用/ _replicate。无论我在我的请求的“源”字段中输入,其附加的“http:127.0.0.1:5984 /”来源网址(或名称),很明显,我得到一个错误说,它不能找到源分贝。当然。

我的问题(这是,顺便说一句,我在计算器上的第一个问题,所以请放纵)则是:我怎么能指向正确的数据库?谢谢!

let url = `http://127.0.0.1:5984/_replicate`;
let data = {
    // This is where I struggle
    "source" : "http://127.0.0.1:8081/_pouch_local_db",
    "target" : `http://127.0.0.1:5984/mydb-${username}`
}
fetch(url, {
    method: 'POST',
    body: JSON.stringify(data),
    headers: {
      'Content-Type': 'application/json',
    },
    credentials: 'include',
  }).then(response => {
    console.log('Success syncing: ', response);
  }).catch(error => console.error('Error while syncing: ', error));
couchdb replicate
1个回答
0
投票

您的代码表明你所要求的CouchDB与当地PouchDb数据库复制?作为PouchDb旨在为客户端数据库系统,该系统将无法正常工作。在正常使用中,PouchDb不是服务器(我知道有可用的PouchDb服务器,但我不认为这是帮助在这里)。

您应该使用PouchDb API(包括在你的JavaScript代码的PouchDB库),并告诉您的本地PouchDb数据库在端口5984 CouchDB的服务器进行复制。

我希望你的代码如下所示:

var dblocal = new PouchDB('local_db');
var dbremote = new PouchDB('http://127.0.0.1:5984/myremotedb');
dblocal.replicate.to(dbremote, function (err, result) {
  if (err) { return console.log(err); }
  // handle 'completed' result
});

我假设你没有密码保护你的测试数据库的CouchDB。如果你有,你就需要使用新的PouchDB时,包括用户名和密码在远程数据库中的“身份验证”选项。

有对PouchDB site一些例子和信息。

© www.soinside.com 2019 - 2024. All rights reserved.