gpt4 book ai didi

ios - 如何在 Firebase iOS 中过滤搜索

转载 作者:行者123 更新时间:2023-11-30 12:26:23 25 4
gpt4 key购买 nike

如何根据条件过滤 Firebase 查询。我已经尝试过这段代码

    let productsQuery = FIRDatabase.database().reference().child("Products").queryLimited(toFirst: 10)
//method 1
productsQuery.queryEqual(toValue: "Pending", childKey: "Status")
//method 2
productsQuery.queryOrdered(byChild: "Status").queryStarting(atValue: "Pending").queryEnding(atValue: "Pending")

但它总是返回庞大的整个集合(超过 10k 条目)

我只想获取“Status”=“Pending”的对象

Backend shown here

我确信 Firebase 中存在这样的基本过滤。请告诉我。

最佳答案

您需要以这种方式组合 queryOrdered(byChild:)queryEqual(toValue:) 并使用 .observeEvent

let productsQuery = FIRDatabase.database().reference().child("Products")
productsQuery.queryOrdered(byChild: "Status").queryEqual(toValue:"Pending")
.queryLimited(toFirst: 10).observeSingleEvent(of: .value, with: { (snapshot : FIRDataSnapshot) in


})

关于ios - 如何在 Firebase iOS 中过滤搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44157827/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com