如何将FirebasFiresore. DocumentSnapshot转换为列表/地图以供事后解析?
每个文档中字段的数量各不相同,因此无法手动完成。
文档中没有任何有用的内容:
exports.userDetailsForm = functions.firestore.
document('responseClientDetails/{details}').onCreate((snap, context) => {
const newValue = snap.data();
const caseReference = snap.id;
return Promise
});
如您参考的文档中所述,DocumentSnapshot
将返回“包含文档中所有字段的对象”。
如果要将此对象转换为地图,可以使用SO答案中描述的一些技术。例如:
var docRef = db.collection("cities").doc("SF");
docRef.get().then(function(doc) {
if (doc.exists) {
console.log("Document data:", doc.data());
for (let [key, value] of Object.entries(doc.data())) {
console.log(`${key}: ${value}`);
}
} else {
// doc.data() will be undefined in this case
console.log("No such document!");
}
}).catch(function(error) {
console.log("Error getting document:", error);
});