Problem with Sorting and Filtering

What I would like to achieve is finding all records that match a pair of strings and sorted by a name tag. The data looks something like:

{
    type:"user",
    name:"Borrden",
    description:"Supreme Ruler of the Codebase",
    filters:[["department", "development"], ["location", "Internet"]]
}
{
    type:"user",
    name:"Skallagorm",
    description:"NoSQL Noob",
    filters:[["department", "development"], ["location", "London"], ["club", "Young Chelsea"]]
}
{
    type:"user",
    name:"James Piercey",
    description:"Elusive",
    filters:[["department", "design"], ["location", "Europe"]]
}

Filtering by [“department”, “development”] should return “Borrden” and “Skallagorm”. Filtering by [“department”, “development”] and [“location”, “London”] should return “Skallagorm”.

Can I achieve this with some combination of map, reduce and setting the keys on the query or do I have to do some sorting in filtering after receiving the result set from the query?

Thanks

You could set a map function to emit each one of the subarrays inside the filters array:

(doc, emit) => 
{
    var filters = doc.UserProperties["filters"] as IList;
    foreach(IList filter in filters) {
        emit(filter, name);
    }
}

That would let you query on any of the keys inside the filters array the way you are describing. The code I wrote is just off the top of my head so the casts may need to be tweaked.