简体   繁体   English

Couchdb:阅读Java中的视图

[英]Couchdb: Read a View in Java

I am using couchdb for first time but I am facing a problem that I cannot find how to solve. 我是第一次使用Couchdb,但遇到了无法解决的问题。 I am creating an ad-hoc view with the following line 我正在使用以下行创建临时视图

ViewResults resultAdHoc = db.adhoc("function(doc) {emit(null, doc.name);}");

when I am running the function with futon I am getting the names in the value side, so I guess it is correctly written. 当我用futon运行函数时,我会在值端获取名称,因此我猜它是正确编写的。 The form of one document is the following 一份文件的格式如下

{
   "_id": "d11d7fa59d162658b7cc95c34a001ce0",
   "_rev": "1-a4038d7061988c7552f9b8b435bba9bf",
   "name": "MyName",
   "session": "549C6567BE25D96EA1D2553C4A9DE175"
}

This that I cannot figure out is how to read this so I could get all the names of the documents in Java for further processing (eg to print them); 我不知道这是如何阅读的,因此我可以获取Java中所有文档的名称以进行进一步处理(例如打印它们)。

ps I am using the CouchDB4J ps我正在使用CouchDB4J

I haven't tried this, but something like this should work 我没有尝试过,但是这样的事情应该可以工作

ViewResults resultAdHoc = db.adhoc("function(doc) {emit(null, doc.name);}");
for (Document d: resultAdHoc.getResults()) {
    String name = d.getString("value");
    ....
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM