Using Java to Perform a Multi-Key Get on a Couchbase View

user1
{
“name”:“name1”,
“age”:23
}
user1
{
“name”:“name2”,
“age”:22
}

how to query find by name and can pass parameter,
such as
public List findByName(String name){

}

my english is very pool,i hope you can understand,thanks

Hi,
what you want maybe is:

  1. create a view which gives you a list of IDs for the name ala

function(doc, meta) {
if (doc.type == “user”) { // or whatever identifies your documents
emit(null, null);
}
}

Now because the ID always comes with the row you dont need to emit it again and shave off some index space.

Now in your SDK you do:

new Query().setIncludeDocs(true);

and then you query it and you can access the document from ViewRow.getDocument!

How do we implement a query that used to be in Oracle to pull all records <= sysdate? We are finding hard to implement this in Couchbase. Pulling all records from CB and comparing for sysDate in java code is impossible. Any help on this is much appreciated!

Below is my scenario :

There are session documents that contain fields like ‘Status’,‘Type’ and ‘CreatedDate’.
I want all the session documents where status is “Active” , Type is {:someType} and CreatedDate >= {:someDate}

@brajput24 you can use either a view where the key is the date/time you want to compare against, and then you can use an end range of your sysdate. This will give you all docs that are <= the sysdate. Or you use N1QL if you are currently developing and can wait until 4.0 is GA. But I think your use case can be done quite nicely with views too.