That’s not a legal map function — it’s using a value from the outside (type). A map function has to be a pure function whose behavior depends only on its input (the document parameter.)
The map function runs while indexing new documents. It does not run at query time. Our documentation goes into detail on this.
No. You’re building an index. In the map function, emit the document’s type as the key. Then when querying, set the query’s key to the type you want to search for.
Again, please read the documentation describing how views and queries work. It’s different than what you’re used to.