gpt4 book ai didi

android - whereArrayContains 限制为 10

转载 作者:行者123 更新时间:2023-12-02 12:46:18 25 4
gpt4 key购买 nike

我想根据 tagIDs 过滤 questionCollection 。一切正常,但 whereArraycontains 最多可处理 10 个 ID。

我怎样才能改进我的结构以处理超过 10 个 tagID 并确保尽可能少地调用服务器以减少金钱支出.

Firestore-root
|
--- questions (collection)
| |
| --- qid (documents)
| |
| --- title: "Question Title"
| |
| --- qid: "autogeneratedID"
| |
| --- tagIDs =[tagID_1,tagID_2...tag_IDs_5] // array
|
--- tags (collection)
| |
| --- tagID (documents)
| |
| --- tagName: "Mathematics"
| |
| --- tagID: "autogeneratedID"
|

获取包含特定 tagID 的问题(如果 tagID 大于 10 则失败)

private fun fetchQuestion(tagMap: HashMap<String, String>) {

val tagIDList:MutableList<String> = ArrayList();
for ((key) in tagMap) {
tagIDList.add(key);
}
var query: Query = db.collection(Constants.QUESTION_COLLECTION)
.orderBy(Constants.KEY_QUESTION_ID, Query.Direction.DESCENDING).limit(50)
if(!tagIDList.isNullOrEmpty())
query = query.whereArrayContainsAny("tagIDs", tagIDList);//if list greater than 10 it's not working

query.get().addOnSuccessListener { queryDocumentSnapshots ->
if(!queryDocumentSnapshots.isEmpty){
for (documentSnapshot in queryDocumentSnapshots) {
val question = documentSnapshot.toObject(QuestionBO::class.java)
}
}
}.addOnFailureListener { e ->
toast("No record found.")
e.printStackTrace()
}
}

最佳答案

documentation for whereArrayContains查询非常具体。它只能处理 10 个数组项:

use the array-contains-any operator to combine up to 10 array-contains clauses on the same field with a logical OR

您应该知道 whereArrayContains 不会减少计费文档读取次数。如果您的数组包含 10 个项目,它仍然需要 10 次文档读取。如果您执行 10 个 whereArrayContains 查询,每个查询有 10 个数组项,它仍然需要 100 次读取。

如果您需要 N 个文档,没有捷径可以使 N 个文档读取的成本低于 N 个文档读取的成本。

关于android - whereArrayContains 限制为 10,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59658641/

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