简体   繁体   English

如何在 firebase 中编写复合查询?

[英]How do I write a compound query in firebase?

I have the following typescript for looking up a city based on its population...我有以下 typescript 用于根据人口查找城市...

import { getFirebase } from "react-redux-firebase";

...

  get fb() {
    return getFirebase();
  }
  get fs() {
    return this.fb.firestore();
  }

  getCollection(collectionName: string) {
    return this.fs.collection(collectionName);
  }
...
firestore.collection("cities").where("population", "<", 100000)

What if I wanted to add a clause to look up a city by its population AND restrict the state to California?如果我想添加一个按人口查找城市并将 state 限制在加利福尼亚州的条款怎么办? (My state column is called "CA")? (我的 state 列称为“CA”)?

If you're working with the data as shown in the documentation on compound queries , then just add another where clause, which creates a logical AND condition:如果您正在使用复合查询文档中所示的数据,则只需添加另一个 where 子句,它会创建一个逻辑 AND 条件:

firestore
    .collection("cities")
    .where("population", "<", 100000)
    .where("state", "==", "CA")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM