Multiple keys search in couchbase view


#1

Can we pass multiple keys in couchbase view, when we are returning multiple keys from view.
Like we want to search users from more than one cities e.g. users from New York, London, Lahore.
And we want to sort the user by date of birth, so how we will pass the keys in the view, so that we can get the user from the mentioned cities and sorted by date of birth.
view definition is below:
function (doc, meta) {
if(doc.doc_type==“user” && doc.status==”Active”)
{
emit([doc.city,doc.date_of_birth],doc);
}
}


#2

Yes, you can conditionally emit based on specific criteria. For example:

function(doc,meta){
if(doc.item){
if(doc.vendor){
emit(doc.vendor, doc.item);
}
if(doc.category){
emit(doc.category, doc.item);
}
if(doc.discount){
emit(doc.discount,doc.item);
}
}
}