I have this in my view function:
emit([doc.address.country,doc.address.state, doc.address.city], doc);
When I query the search, I need to have all 3 elements of the array filled in, for example:
?key=["US","NY","New York"]
that will produce my records, but lets say for example, I just want to return everything in the US for example:
?key=["US"]
or in the US and State...
?key=["US","NY"]
OR... lets say perhaps I want just all records from NY... (i know the below doesn't work)
?key=["","NY"]
I don't really get how to search if you want to leave one of the elements of the array empty?
First:
key=["US"] will not work on an Array Key ["US","NY"], cause you're looking for a key that is EXACT ["US"]. Instead, you have to use
then those Keys are in the resultset:
Also Working:
result:
Second: You cannot have blanks on left side.. so you have to write some more emits: ( you do not have to emit the second and third array-item, if you do not need to query it)
view "byStateCityCountry":
view "byCityStateCountry":
of just put a flag in the first place to determine the type of query, so you can do all in one View:
Usage: