简体   繁体   中英

How to fetch nested map fields in a Firestore Document

I've been using Firestore in Firebase and for now i've been able to extract the whole document but I can't extract one of the variables (for example, latitude): Firestore 文档截图

文档输出示例

And here is my code that works (JavaScript with React Native and Expo):

let cityRef = db.collection('pacientes').doc('paciente-test');
let getDoc = cityRef.get()
.then(doc => {
if (!doc.exists) {
  console.log('No such document!');
} else {
  console.log(doc.id, " => ", doc.data());
}
})
.catch(err => {
console.log('Error getting document', err);
})

I tried many things with doc.data(), like doc.data().latitude (with an undefined output) but whenever I change it, it doesn't compile. I've seen other solutions around but they don't work for me for some reason. If you think I've missed any info that could be more helpful let me know

Your document contains a single field called "safeArea" which has nested properties. You have to reference those nested properties as object properties in the "safeArea" object, like this:

doc.data().safeArea.latitude

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