简体   繁体   中英

Retreive document data Firestore using React

My goal is to read a document in the Firebase Firestore database using React. I would like to get all the information within a certain document like the date of the last export. The only thing I was able to get back is a big confusing array. In this test, I tried to read if a certain activation code has already been used, and when it was used. My Firestore database has the following structure:

Firestore database structure and document

When I execute the following code:

firebase
      .firestore()
      .collection('Codes')
      .doc('00000')
      .get()
      .then((result) => {
        console.log(result);
      })
      .catch((err) => {
        console.log('Error getting documents', err);
      });

I get back the following result

The only thing I was able to see is the document ID, and a confirmation that the document exists. To communicate to the database, I used a library called React-firebase-js. If anyone can help me in the right direction, it would be greatly appreciated!

firebase
      .firestore()
      .collection('Codes')
      .doc('00000')
      .get()
      .then((result) => {
        console.log(result.data())
      })
      .catch((err) => {
        console.log('Error getting documents', err);
      });

https://firebase.google.com/docs/firestore/query-data/get-data

need to call result.data() as per the above documentation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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