DocumentReference.get(<Field>)不起作用

我只是想找到这个布尔值,如果它是true,那么它将执行代码。否则,它将执行另一个代码。我似乎无法在Firebase中读取此布尔值。

This is the data I am trying to read.

它说here我可以做.get(fieldPath),但是我做错了。 Firebase文档确实很糟糕。哈哈

checkIfLoggedIn = () => {
    firebase.auth().onAuthStateChanged(user => {
      if (user) {
        const uid = firebase.auth().currentUser.uid;
        const db = firebase.firestore();
        db.collection('users')
          .doc(uid)
          .get('uid.isStore')
          .then(snapshot => {
            // Trying to find how to do this
            console.log(snapshot);
          });
        this.props.navigation.navigate('mainNav');
      } else {
        this.props.navigation.navigate('signup');
      }
    });
  };

sdadaadfaaf 回答:DocumentReference.get(<Field>)不起作用

我认为您想要的逻辑类似于:

db.collection('users')
  .doc(uid)
  .get()
  .then(documentSnapshot => {
    let isStore = documentSnapshot.get('isStore');
    // Value of isStore here ... 
  });

链为:

  • db.collection-> CollectionReference
  • CollectionReference.doc()-> DocumentReference
  • DocumentReference.get()-> Promise<DocumentSnapshot>
  • DocumentSnapshot.get()->字段值

另请参阅:

本文链接:https://www.f2er.com/3133900.html

大家都在问