2
我有一個要求,我已經從couchbase中獲取文檔。如何使用couchbase中的視圖獲取文檔
繼我使用了相同的地圖功能 -
function (doc, meta) {
if (meta.type == "json" && doc!=null) {
emit(doc);
}
}
有沒有降低的功能。另外下面是我的Java代碼來獲取文件 -
List<URI> hosts = Arrays.asList(
new URI("http://<some DNS with port>/pools")
);
// Name of the Bucket to connect to
String bucket = "Test-Sessions";
// Password of the bucket (empty) string if none
String password = "";
//System.setProperty("viewmode", "development");
// Connect to the Cluster
CouchbaseClient client = new CouchbaseClient(hosts, bucket, password);
String designDoc = "sessions";
String viewName = "by_test";
View view = client.getView(designDoc, viewName);
Query query = new Query();
query.setIncludeDocs(true);
query.setKey(String.valueOf(122));
ViewResponse result = client.query(view, query);
Object object = null;
for(ViewRow row : result) {
if(null != row) {
object = row.getDocument();
}// deal with the document/data
}
System.out.println("Object" + object);
和數據,我在couchbase是關鍵 - 「122」和價值 - 「真」。但由於某種原因,ViewResponse中沒有任何行。出什麼事了,誰能幫忙?