私のクラウド機能にドキュメントが存在するかどうかをチェックする方法を探しています 既存の値をインクリメントするときに私の機能はうまく動作しますが、以前の値が存在するかどうかをチェックし、1に設定されていないかどうかを確認する機能です。Firebaseクラウド機能が存在しないデータのためにdbをチェックする
私は別の方法を試みましたが、 "snapshot.exists"や "TypeError: docRef.get.then.snapshot
以下var getDoc = docRef.get()
.then(snapshot => {
if (typeof snapshot._fieldsProto.count !== undefined) {
console.log("haha3", snapshot._fieldsProto.count)
var count = Number(jsonParser(snapshot._fieldsProto.count, "integerValue"));
docRef.set({
count: count + 1
});
}
else {
docRef.set({
count: 1
});
}
});
における未定義のカウントが」存在()のエラーコードである
var getDoc = docRef.get()
.then(snapshot => {
if snapshot.exists() {
console.log("haha3", snapshot._fieldsProto.count)
var count = Number(jsonParser(snapshot._fieldsProto.count, "integerValue"));
docRef.set({
count: count + 1
});
}
else {
docRef.set({
count: 1
});
}
});
このコードのエラーは次のとおりです。
TypeError: snapshot.exists is not a function at docRef.get.then.snapshot
文書は、スナップショット呼び出し[ 'DocumentSnapshot.exists()'](https://firebase.google.com/docs/reference/jsに存在するかどうかを確認するには/firebase.firestore.DocumentSnapshot#~exists)。それがうまく行かない場合は、正確なエラーメッセージと[エラーを再現する最小完全コード](http://stackoverflow.com/help/mcve)を表示してください。 –
存在エラーのコードを追加しました – Blue
そのコードで発生するエラーは何ですか? –