[英]Retreive document data Firestore using React
My goal is to read a document in the Firebase Firestore database using React.我的目标是使用 React 阅读 Firebase Firestore 数据库中的文档。 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 数据库具有以下结构:
Firestore database structure and document Firestore 数据库结构和文档
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.我唯一能看到的是文档 ID,以及文档存在的确认。 To communicate to the database, I used a library called React-firebase-js.
为了与数据库通信,我使用了一个名为 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 https://firebase.google.com/docs/firestore/query-data/get-data
need to call result.data() as per the above documentation需要根据上述文档调用 result.data()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.