gpt4 book ai didi

swift - 火存储 : query with array comparison

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

我正在尝试实现类似 ref.whereField("userID", existsIn: friendArray) 的目标,这将允许我从用户集合中过滤掉 friend 。我知道不支持这样的查询。客户端解决方案,例如 db.collection("users").getDocuments() { //iterate documents }可能对数据不太友好,有服务器端解决方案吗?

最佳答案

虽然您没有显示文档结构,但我想您目前有类似的内容:

{
"user_name": "Jon Doe",
"friendArray": [{
0: "userID",
1: "userID2",
2: "userID3"
}]
}

但是Firestore Docs建议将数据结构化为:

{
"name": "Jon Doe",
"friendArray": {
"userID": true,
"userID2": true,
"userID3": true
}
}

这样,您就可以使用以下方法检索好友列表中具有 userID 的所有用户:

db.collection("users")
.whereField("friendArray.userID", isEqualTo: true)
.getDocuments() { (querySnapshot, err) in

// ...

}

关于swift - 火存储 : query with array comparison,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51449045/

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