gpt4 book ai didi

java - 我可以在 firestore 查询中设置多个 .whereEqualTo 指向文档中的字段吗?

转载 作者:行者123 更新时间:2023-12-02 01:10:26 26 4
gpt4 key购买 nike

我有一个以city 作为字段的文档。我想查询一个包含

的文档

城市==“东京”和城市==“大阪”

如何做到这一点?

我已经尝试过这个:

query = ref
.whereEqualTo(FIRESTORE_EVENT_FIELD_CITY,"Tokyo")
.whereEqualTo(FIRESTORE_EVENT_FIELD_CITY,"Osaka")
.whereEqualTo(FIRESTORE_EVENT_FIELD_IS_ACTIVE,true)
.whereEqualTo(FIRESTORE_EVENT_FIELD_HAS_BEEN_APPROVED,false)
.whereGreaterThanOrEqualTo(FIRESTORE_EVENT_FIELD_DATE_START_TIME,now.toDate())

.whereLessThanOrEqualTo(FIRESTORE_EVENT_FIELD_DATE_START_TIME,oneMonthFromNow.toDate())
.orderBy(FIRESTORE_EVENT_FIELD_DATE_START_TIME, Query.Direction.ASCENDING)
.limit(limit)

但是我没有收到任何文档,如果我只设置一个指向的查询一个城市,就像这样 .whereEqualTo(FIRESTORE_EVENT_FIELD_CITY,"Tokyo") ,然后它就可以工作,但它只给我所有在城市字段中有 tokyo 的文档

最佳答案

来自文档:

You can only perform range comparisons (<, <=, >, >=) on a single field, and you can include at most one array-contains or array-contains-any clause in a compound query

https://firebase.google.com/docs/firestore/query-data/queries

citiesRef.whereGreaterThanOrEqualTo("state", "CA")
.whereLessThanOrEqualTo("state", "IN");
citiesRef.whereEqualTo("state", "CA")
.whereGreaterThan("population", 1000000);

关于java - 我可以在 firestore 查询中设置多个 .whereEqualTo 指向文档中的字段吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59485296/

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