Map/Reduce in PouchDB/CouchDB does have a "closed scope"--it's not the lamda it looks like.
Essentially, you don't query with the map/reduce...you build an index.
In CouchDB parlance, the map/reduce code is called a view. The thing it builds is an index. You then query the index using a...query. 😉
In CouchDB it's clearer than in PouchDB as you actually use query params to query an index (which lives at a URL, so it's more obviously a stored something or other that you're querying via HTTP).
In PouchDB, the first part of .query()
works like a "save this view + build an index for it" action, the second part are the "query params" from CouchDB land.
Check the code again to see if it makes more sense.