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

时间:2019-11-09 05:45:45

标签: javascript firebase react-native google-cloud-firestore

我只是想找到这个布尔值,如果它是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');
      }
    });
  };

1 个答案:

答案 0 :(得分:0)

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

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()->字段值

另请参阅: