0

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

问题是我无法获取用户名和密码。顺便说一句,另一个问题是,当 servlet 发送 jsonarray 例如命名数据时,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));
}
4

1 回答 1

0

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

或者查看“_all_docs?include_docs=true”,因为“_all_docs”本身不返回数据,只返回像ids这样的文档信息。

于 2014-04-16T11:54:39.790 回答