我使用 CouchDB 作为我的数据库,并且我可以通过我的 RESTful Web 服务器向其中添加新文档。
我现在正在尝试将附加信息添加到我添加的文档中,但我不太清楚如何将其发布到正确的文档中。我所能做的就是添加新文档或通过 PUT 覆盖它们。
这就是我发布新文档的方式:
@POST
@Path("/{_id}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response postBetroffenePerson(@PathParam("_id")String _id, Person person){
Betroffene betroffene = new Betroffene(_id, person);
String betroffenePerson = gson.toJson(betroffene);
JsonObject betroffenePerson1 = gson.fromJson(betroffenePerson, JsonObject.class);
db.postObject(betroffenePerson1);
return Response.noContent().build();
}
db 是我的数据库:
public void postObject(JsonObject object) {
dbBetroffeneClient.save(object);
}
现在,除了 ID 和人员之外,我还想向“Betroffene”添加其他信息。
我还有一个 GET 方法可以通过他们的 id 获取特定的“Betroffene”。
最佳答案
修改 CouchDB 文档的唯一方法是获取它,在内存中修改它,然后替换它(使用 PUT)。这是设计使然;没有用于修改文档特定字段的 API。
关于java - 将内容添加到 Couchdb 中的文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21188159/