Couchbase 通过同步网关创建文档失败 public rest API
Couchbase create document fails through sync-gateway public rest API
根据 Couchbase Sync-Gateway REST API 文档 here 下面提到的 cURL 应该在指定的数据库中创建一个文档。
下面是 Postman 生成的 cURL。
curl -X PUT -H "Cache-Control: no-cache" -H "Postman-Token: 498d0fb6-77ac-9335-2379-14258c6731c7" -d '' "http://192.168.244.174:4984/db/"
我还尝试将 JSON 添加到请求正文中。
但是当我通过 Postman 发送放置请求时,它没有创建新文档,而是尝试创建一个新数据库并且 JSON 响应是
{
"error": "Precondition Failed",
"reason": "Database already exists"
}
我是漏掉了什么还是一个错误?有没有其他方法可以创建文档同步网关?
文档中有错误。
根据文档,
You can either specify the document ID by including the _id object in the request message body, or let the software generate an ID.
但是 Couchbase REST API 似乎不是那样工作的(可能是他们没有定期更新文档)。您需要在 URL 中提供 id,例如 /{db}/{id}
。
下面的 cURL 对我有用。
curl -X PUT -H "Content-Type: application/json" -H "Cache-Control: no-cache" -H "Postman-Token: 75ab844e-5130-708e-69e9-e87f878108b4" -d '{"name": "xxx",
"full_name": "xxx yyy"}' "http://192.168.244.174:4984/db/123"
JSON 响应是
{
"id": "123",
"ok": true,
"rev": "1-9324dabc947fc963a754b113d1215ac3"
}
根据 Couchbase Sync-Gateway REST API 文档 here 下面提到的 cURL 应该在指定的数据库中创建一个文档。
下面是 Postman 生成的 cURL。
curl -X PUT -H "Cache-Control: no-cache" -H "Postman-Token: 498d0fb6-77ac-9335-2379-14258c6731c7" -d '' "http://192.168.244.174:4984/db/"
我还尝试将 JSON 添加到请求正文中。
但是当我通过 Postman 发送放置请求时,它没有创建新文档,而是尝试创建一个新数据库并且 JSON 响应是
{
"error": "Precondition Failed",
"reason": "Database already exists"
}
我是漏掉了什么还是一个错误?有没有其他方法可以创建文档同步网关?
文档中有错误。
根据文档,
You can either specify the document ID by including the _id object in the request message body, or let the software generate an ID.
但是 Couchbase REST API 似乎不是那样工作的(可能是他们没有定期更新文档)。您需要在 URL 中提供 id,例如 /{db}/{id}
。
下面的 cURL 对我有用。
curl -X PUT -H "Content-Type: application/json" -H "Cache-Control: no-cache" -H "Postman-Token: 75ab844e-5130-708e-69e9-e87f878108b4" -d '{"name": "xxx",
"full_name": "xxx yyy"}' "http://192.168.244.174:4984/db/123"
JSON 响应是
{
"id": "123",
"ok": true,
"rev": "1-9324dabc947fc963a754b113d1215ac3"
}