【发布时间】:2021-03-16 11:01:02
【问题描述】:
我正在尝试根据任务(任务)的名称检查我要添加的任务是否已存在于 firestore(任务集合)中。当我显示 documentSnapshot.exists 时,它是未定义的
addTask=async(task)=>{
var useruid=firebase.auth().currentUser.uid;
console.log("task : "+task);
try{
await firebase.firestore().collection("Tasks").where('task','==',task).get().then(documentSnapshot=>{
{console.log('Task exists : ',documentSnapshot.exists)}
if(documentSnapshot.exists)
{console.log('This task already exists!')}
else{
firebase.firestore().collection('Tasks').add({userProducer:useruid,task:task}).then(() => {
console.log('Task added!');
})
}
})
}
catch(error){
console.log("error = "+error)
}
}
【问题讨论】:
标签: javascript firebase react-native google-cloud-firestore