gpt4 book ai didi

firebase - 云函数 : check if document exists always return exists

转载 作者:行者123 更新时间:2023-12-04 06:55:06 25 4
gpt4 key购买 nike

我正在使用此云功能(Typescript)检查文档是否存在。
问题:文档不退出,它返回存在....

非常感谢您的帮助和努力!

export const repeat2 = functions.https.onCall((data, context) => {

console.log(data.message);
console.log(data.count);

const getDocument = admin.firestore().collection('key').doc(data.message).get();

if(getDocument != null) {
console.log('EXISTS');
}

else {console.log("doens't exist");}

return {
repeat_message: data.message,
}
});

最佳答案

get()返回一个 Promise,而不是实际的文档。另外,您需要使用 .exists在解析值上;检查 the docs here :

var docRef = db.collection("cities").doc("SF");

docRef.get().then(function(doc) {
if (doc.exists) {
console.log("Document data:", doc.data());
} else {
// doc.data() will be undefined in this case
console.log("No such document!");
}
}).catch(function(error) {
console.log("Error getting document:", error);
});

关于firebase - 云函数 : check if document exists always return exists,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57655190/

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