Getting confusion on Couchbase Lite VIEWS

Hi Guys, i’m getting a bit confusion on VIEWS, because i have documents for userProfile, here is the code snippet.

`func createViewWithName(viewname: String){
// Create a view and register its map function:
let phoneView = Constants.appDeleRef.database.viewNamed(viewname)
phoneView.setMapBlock({ (doc, emit) in

            if let nameObj: AnyObject = doc["userName"] {
                if let name = nameObj as? String {
                    emit(name, doc)
                }
            
        }
        }, version: "2")
}`

i will pass VIEW name as “userProfile”, for my user profile document have following keys.
userName, Email, Password, Address.

so when i use above view, i’m getting all documents related to my userProfile

Here is my Queries

  1. I’m getting all docs, whatever documents contains “userName key”. if some other documents like userMoreDetails have same keys, will those docs also come with above VIEW request? if it is come, how can i restrict some documents only for userProfile and some only for userMoreDetails as like relational database tables.

  2. if i do any modification(changing of VIEW request like change to email) on my Existing code of View, i’m not able to perform the above VIEW, so every time, im changing my VIEW name, is there any alternative to update the VIEW code.

  3. i want to do query like, matching username and password entered by user on iOS app. i want to check any doc matches with these credentials. i seen QUERY in couchbaselite, but here getting all docs and checking on while loop, is it right way to check the result. because i though it takes some bit long time.

  4. How to use rest API on my Couchbase Server db. like the query check username and password on my userProfile Document by using Rest API.

  5. Can we create a lookup documents from index.html page, i seen an option called created document. if we will create a doc form admin portal, what are the required keys for that and how its will match with my userProfile document.