如何将 FirebaseFirestore.DocumentSnapshot 转换为列表/映射以供事后解析?
每个文档中的字段数量各不相同,因此无法手动完成。
documentation 中没有任何有用的内容:
exports.userDetailsForm = functions.firestore.
document('responseClientDetails/{details}').onCreate((snap, context) => {
const newValue = snap.data();
const caseReference = snap.id;
return Promise
});
最佳答案
如 doc 中所述您提到,DocumentSnapshot
将返回“包含文档中所有字段的对象”。
如果您想将此对象转换为 map ,您可以使用此SO answer中描述的一些技术。 。例如:
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);
});
关于javascript - 将 FirebaseFirestore.DocumentSnapshot 转换为 Node.js 中的列表/ map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57758591/