繁体   English   中英

FireStore 查询不返回任何内容

[英]FireStore Query Return Nothing

我已经对我的用户进行了身份验证,并希望他们对某些选项进行轮询。 每个经过身份验证的用户都将在集合中的文档中注册。 这是一个无服务器前端反应应用程序。

const handleSubmit = async () => {
  try {
    await setDoc(doc(db, "data", user), {
      user: user,
      behave: choice === "behave" ? 1 : 0,
      grimace: choice === "grimace" ? 1 : 0,
    });
  } catch (e) {
    console.log(e.message);
  }
  try {
    const q = query(collection(db, "data"), where("uid", "==", user));
    const snapShot = await getDocs(q);
    snapShot.forEach((doc) =>
      console.log(doc)
    )
  } catch (e) {
    console.log(e.message);
  }
}

我的想法是我想通过引用用户的 uid 来避免重复轮询。 查询数据时,我没有看到任何错误消息,也没有看到任何console.log(doc) ,请告诉我我做错了什么。

您正在将用户 ID 添加为文档中的user ,然后在字段uid上进行查询。 将字段名称设置为uid或将查询更改为user字段,如下所示:

await setDoc(doc(db, "data", user), {
  uid: user, // <-- set field name to UID
  // ...
});


// query on "uid" field
const q = query(collection(db, "data"), where("uid", "==", user));

暂无
暂无

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

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