如何在flutter中调用Firebase Firestore特定文档ID,并在集合中调用特定字段? [英] How to call firebase firestore specific document ID in flutter and specific field in collection?

查看:166
本文介绍了如何在flutter中调用Firebase Firestore特定文档ID,并在集合中调用特定字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的Firestore Firebase中的图像.我想调用文档ID和特定类型.

This is the image from my firestore firebase. and i want to call the document id and specific type.

我还是扑朔迷离.我对如何调用要在我的应用中显示的文档ID和特定字段有疑问.

I am still new in flutter and firebase. I have a question on how to call document id and specific field to be display in my apps.

推荐答案

如果您想阅读单个用户文档,则(网络示例)

if you want to read single user document then (web example)

var docRef = db.collection("User").doc(SingleUserUID);
docRef.get().then((doc) => {
    if (doc.exists) {
        console.log("Document data:", doc.data());
    } else {
        // doc.data() will be undefined in this case
        console.log("No such document!");
    }
}).catch((error) => {
    console.log("Error getting document:", error);
});

如果要查询所有用户类型老师"

if you want to query for all user type "teacher"

var docRef = db.collection("User");
var query = citiesRef.where("type", "==", "teacher").limit(10);
query.get()
    .then((querySnapshot) => {
        querySnapshot.forEach((doc) => {
            // doc.data() is never undefined for query doc snapshots
            console.log(doc.id, " => ", doc.data());
        });
    })
    .catch((error) => {
        console.log("Error getting documents: ", error);
    });

并使用limit限制查询中返回结果的数量

and use limit to limit number of result return in a query

有关更多信息,请阅读文档,网址为

for more info read documentation at

  1. https://firebase.google.com/docs/firestore/query-数据/
  2. https://firebase.google.com/docs/firestore/query-数据/查询

对于Flutter

 var query = citiesRef.where("type",isEqualTo:"teacher").limit(10);

  1. https://firebase.flutter.dev/docs/firestore/usage#document--查询快照

这篇关于如何在flutter中调用Firebase Firestore特定文档ID,并在集合中调用特定字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆