gpt4 book ai didi

javascript - 将 FirebaseFirestore.DocumentSnapshot 转换为 Node.js 中的列表/ map

转载 作者:行者123 更新时间:2023-12-02 23:01:38 25 4
gpt4 key购买 nike

如何将 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com