从couchdb检索数据



我是新的couchdb用户,我正在使用lightcouch API
目前,我可以从couchdb获取数据,但我能得到的不是我需要的。您可以看到以下代码:用户名值和密码值被存储,这两个值需要存储到jsonaray中
然而,问题是当我尝试打印数据时,它只显示了以下内容:
{"id":"0a3f38cfc5ca45d6bcd76725faf5b917","key":"0 a3f38cvc5ca45d 6bcd76725 faf5b9157","value":{"rev":"1-32d4a8325e8995d0eddd5b2626b752df"}}

问题是我无法获得用户名和密码。顺便说一句,另一个问题是,当servlet发送例如命名数据的jsonaray时,jquery如何从数据中获取消息和用户名。

CouchDbProperties properties = new CouchDbProperties(
        "db_test",
        true,
        "http",
        "127.0.0.1",
        5984, null, null);

CouchDbClient dbClient2 = new CouchDbClient(properties);
Map<String, Object> map = new HashMap<>();
map.put("username", "justin");
map.put("message", "hello world");
dbClient2.save(map);
List<JsonObject> jsonList = dbClient2.view("_all_docs").query(JsonObject.class);
for (int i=0; i< jsonList.size(); i++){
    System.out.println(jsonList.get(i));
}

您可以在CouchDb中指定"视图",在这种情况下,您可以将视图路径指定为"_design/something/_view/someview",而不是"_all_docs"。有关视图的更多信息https://wiki.apache.org/couchdb/Introduction_to_CouchDB_views

或者查看"_all_docs?include_docs=true",因为"_all_docs"本身不返回数据,只返回id等文档信息。

最新更新