Storing views results within Couchbase, and using them again


#1

Hi all,

I really need some urgent help with this.

I need to apply views on some documents in Couchbase and I need to use these results to pass them to memcached (the one inside Couchbase) and I’m not sure how to do this.

I couldn’t find how to store views results inside Couchbase, it seems that they can only be used as a query, but may be I’m wrong.

and how can I export these results to Memecached, this is really important to know.

Any help is very much appreciated.

Thanks,


#2

Hello,

So what you have to do is, once the view is created:

  • Call the views with the parameters/queries you want to cache/ (this needs to be done from your application)

  • then just take the result of your query call, and store it into Couchbase with a TTL.

Something that looks like (using Java):

Object o = cb.get(“query-result-001”);
if (o == null) {
View view = cb.getView(“brewery”, “by_name”);
Query query = new Query();
query.setLimit(100);
Map<String, String> result = new HashMap<String,String>();
ViewResponse viewResponse = cb.query(view, query);
for (ViewRow row : viewResponse) {
result.put(row.getId(), row.getKey());
}
cb.set(“query-result-001”, 10, json.toJson(result));
}
// deal with the result

Is this the type of information you are looking for?

Regards
Tug
@tgrall


#3

It is, many thanks. however I still have another question:
How to import JSON documents from the file system into couchbase by using java application?