我有一个以city
为字段的文档。我想查询包含city == "Tokyo
”和city == "Osaka"
。
怎么做 ?
我已经尝试过这个了:
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")
,它可以工作,但是它只给我所有在city字段中具有东京的文档 最佳答案
从文档:
您只能在单个字段上执行范围比较(,> =),并且在复合查询中最多可以包含一个array-contains或array-contains-any子句
https://firebase.google.com/docs/firestore/query-data/queries
citiesRef.whereGreaterThanOrEqualTo("state", "CA")
.whereLessThanOrEqualTo("state", "IN");
citiesRef.whereEqualTo("state", "CA")
.whereGreaterThan("population", 1000000);