我正在尝试使用以下代码从Firestore集合中读取数据:
auth.onAuthStateChanged(user => {
if(user) {
console.log('User logged in:', user)
db.collection('MediCorePatientUsers').where("GPID", "==", user.email)
.get().then((snapshot) => {
snapshot.docs.forEach(doc => {
renderPatientList(doc);
})
})
document.getElementById("nameOfUser").innerHTML = user.email;
} else {
console.log('User logged out');
}
});
这段代码按预期工作,并在我的网页上显示正确的数据。然而,我想添加另一个条件到代码中,使用“或”运算符来显示"InsuranceCompany"字段也等于当前用户的电子邮件的数据。
db.collection('MediCorePatientUsers').where("GPID", "==", user.email || "InsuranceCompany", "==", user.email)
.get().then((snapshot) => {
snapshot.docs.forEach(doc => {
renderPatientList(doc);
})
})
然而,当任一条件为真时,这将导致数据均未显示。这段代码有什么问题吗?