Ios 如何使用查询从CouchBaseLite Mobile查找数据?

Ios 如何使用查询从CouchBaseLite Mobile查找数据?,ios,swift3,couchbase-lite,Ios,Swift3,Couchbase Lite,我的文件 let properties: [String : Any] = [ "project_id":Task.project_id!, "title": title, "parent_id": parent_id, "weight": "1", "created_at": DateTime.DateTime(), "updated_at": Dat

我的文件

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!,
        ]
我想根据条件查找数据

我的意思是,我想得到哪个文档,其中parent_id不是nil或null。 我正在使用这个查询

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()
}

但是这个函数返回所有数据。如何执行此任务?

您可以创建一个视图,该视图仅在父项id不是nil时发出条目

或者,你也可以看看,你可以给你你想要的。这将涉及使用reduce函数,并且似乎不太适合您的结构。这需要对地图功能进行一些修改

否则,您可以在迭代查询结果时过滤掉行