How to find data from CouchBaseLite Mobile using query?

my document

let properties: [String : Any] = [
        "project_id":Task.project_id!,
        "title": title,
        "parent_id": parent_id,
        "weight": "1",
        "created_at": DateTime.DateTime(),
        "updated_at": DateTime.DateTime(),
        "type": "group",
        "tag_id":tagId,
        "owner": Session.username!,
    ]

I want to find data according to condition.

I mean, I want to get which document where parent_id is not nil("") or null. I am using this query

func setupViewAndQuery() {

let listsView = database.viewNamed("list/GroupDropDown")

if listsView.mapBlock == nil {
    listsView.setMapBlock({ (doc, emit) in
        if let type: String = doc["type"] as? String, let name = doc["title"], let parent_id = doc["parent_id"] as? String, let created  = doc["created_at"], let updated = doc["updated_at"], let Id = doc["_id"]
            , type == "group", parent_id != "" {
            emit([name,parent_id,created,updated,Id], nil)
        }
    }, version: "1.0")
}

listsLiveQuery = listsView.createQuery().asLive()
listsLiveQuery.addObserver(self, forKeyPath: "rows", options: .new, context: nil)
listsLiveQuery.start()
}

but this function returns all data. how to do this task?
couchBase Mobile 1.4

The view seems fine. So are you sure you have documents that do not meet the “emit” criteria ? If you can share an a doc that you expect to be excluded we can verify against the condition to see why this may not be working.
Also, I would create the view when the db is being created /opened - so that way, you know it’s being created once (and you don’t need the nil checks to verify the same).

You realize that this test will allow documents with no parent_id property, since nil is not equal to an empty string?

Hi

Thanks to reply
I have test all cases but I did not get effective response .
Can you describe me how to find data like sql query
"Select * from document_name where parent_id = ‘5’ "

in couch base mobile 1.4 in swift.

Create a view whose map function emits parent_id as the key (if the document has such a property.)

Query the view, with startKey=“5” and endKey=“5”.