February 2015
Intermediate to advanced
170 pages
3h 39m
English
Writing an AND query requires a different approach than what we used for our OR query. If you wanted to perform the analogue of a SQL query with multiple values in a WHERE clause, you'd need to structure your view keys in such a way as to allow your application to supply multiple values as one key parameter value:
SELECT * FROM Users WHERE LastName = 'Soprano' AND FirstName = 'Tony'
In the preceding SQL statement, we are able to have values for both LastName and FirstName. One approach would be to create a delimited key in our index like this:
function(doc, meta) {
if (doc.type == "user" && doc.firstName && doc.lastName) {
emit(doc.lastName + "," + doc.firstName, null);
}
}This map function emits a key in the form of "Soprano,Tony" ...
Read now
Unlock full access