首页 > 解决方案 > 从 Firestore 集合中获取多个文档时搜索两个查询

问题描述

所以我有

  let dbREF = db
    .collection("Users")
    .doc("mQ4lxHU1sQhKlSmYYkik5F4dapz1")
    .collection("listings");

我有

 dbREF
    .where("state", "==", uState)
    .get()
    .then((querySnapshot) => {

并且我基本上从集合 dbREF 中获取了多个与.where state === uState 匹配的文档。我想弄清楚的是如何搜索两个查询。

我试着这样做

 dbREF
    .where("state", "==", uState && "make", "==", selectedMake)
    .get()
    .then((querySnapshot) => {

但这没有用。我不仅要查找值为 uState 的状态,还要查找值为 selectedMake 的状态。我想知道是否有人可以指出我如何做到这一点的正确方向。非常感谢=]

标签: javascriptfirebasegoogle-cloud-firestore

解决方案


您可以where多次调用,条件将被“与”在一起。所以:

 dbREF
    .where("state", "==", uState)
    .where("make", "==", selectedMake)
    .get()

另请参阅有关复合查询的 Firebase 文档部分。


推荐阅读