【问题标题】:how to access information of particular user from firebase firestore? [closed]如何从 Firebase Firestore 访问特定用户的信息? [关闭]
【发布时间】:2021-03-29 04:36:19
【问题描述】:

我是 Firebase 的新手。我创建了具有字段 id、email、user_name 和 image_url 的集合用户。我也通过注册将记录添加到集合中。但我不知道如何访问登录用户的记录以将当前用户的记录包含在我的应用程序中。

【问题讨论】:

  • "寻求调试帮助的问题('为什么这段代码不工作?')必须包括期望的行为、特定问题或错误必要的最短代码 在问题本身。没有明确的问题陈述的问题对其他读者没有用处。请参阅:@ 987654322@"
  • 我遇到问题具体是什么意思?您遇到困难的代码在哪里?请更新问题,我们会看看。

标签: firebase flutter google-cloud-firestore firebase-authentication


【解决方案1】:
 final _fireStore = FirebaseFirestore.instance;
 String imageURL ;
 String email;
 String imageURL ;

 await _fireStore
          .collection('users')
          .doc(userID)
          .get()
          .then((DocumentSnapshot snapShot) {
        if (snapShot.exists) {
            imageURL = snapShot.data()['img_url'];
            email= snapShot.data()['email'];
            user_name= snapShot.data()['user_name'];
            print('Done Fitching Data From FireStore');
            print(imageURL);
        }
      });

【讨论】:

    【解决方案2】:

    回答标题问题并考虑您的数据库架构,这就是您可以从数据库中读取特定用户的方式。

    FirebaseFirestore.instance.collection('users').doc(userDocumentId).get();
    

    其中 userDocumentId 可以是:“QW9y2GzxJi...”

    【讨论】:

      猜你喜欢
      • 2013-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-27
      • 1970-01-01
      相关资源
      最近更新 更多