I have a set of documents where multiple documents are associated with userids/accounts and each document has a time stamp attribute. I would like to retrieve all documents for an account/userid in a particular date range.
I have my emit function written as below
function (doc, meta) {
var months = { 'Jan':1, 'Feb':2, 'Mar':3, 'Apr':4, 'May':5, 'Jun':6, 'Jul':7, 'Aug':8,'Sep':9, 'Oct':10, 'Nov':11, 'Dec':12
}
var t = doc.TIMESTAMP.split(/[- .]/);
emit([doc.A_NUM,t[2],months[t[1]]], [doc.ID,doc.TIMESTAMP]); // t[2] returns the year and months[t[1]]] returns month
}
Once i have indexed the view, I would like to make a query to retrieve all doc IDs along with one more field TIMESTAMP for a particular A_NUM for last couple of months. SO my input would be something like
Inputs:
start key - [A_NUM, 2014, 6]
end key - [A_NUM, 2014, 4]
List<String> list = new ArrayList<>();
list.add("localhost");
Cluster cluster = CouchbaseCluster.create(list);
Bucket bucket = cluster.openBucket("my-service-data", "");
ViewResult result = bucket.query(ViewQuery.from("contact", "getByANumber").startKey(/*startKey*/).endKey(/*endKey*/));
How should i form startKey and endKey and how my inputs need to be provided here? Could someone please point me to the right example. I have looked at http://docs.couchbase.com/developer/java-2.1/querying-views.html but i could not understand or formulate my case from this doc.