Firestore Where Clause Doesn't Make The Condition.
in my function I have two where clauses. what I want is to check whether a document exits, where two ids are found. but when I run it, it returns all the records of collection. can
Solution 1:
You're not chaining the query clauses correctly. Also, you're calling get() in the middle of your chain. That's almost certainly not what you want. Each query object builds on the last, and you should only get() on the final query in the chain:
setApplyStatus() {
var query = firebase.firestore().collection('applications')
.where("jobSeekerId", '==', this.jobSeekerId)
.where("jobId", '==', this.job.id)
.get().then(querySnapshot => {
querySnapshot.forEach(doc => {
console.log(doc.data())
console.log('already exists')
this.applyStatus = true
})
})
}
Solution 2:
try making an index at firebase for your query since without the index it will fail to bring out your result. You can get the link to make the index at the console in an error so check your console
Solution 3:
setApplyStatus() {
var query = firebase.firestore().collection('applications')
query = query.where("jobSeekerId", '==', this.jobSeekerId)
query = query.where("jobId", '==', this.job.id)
query = query.get().then(querySnapshot => {
querySnapshot.forEach(doc => {
console.log(doc.data())
console.log('already exists')
this.applyStatus = true
})
})
}
Solution 4:
citiesRef.where("state", "==", "CA", "||", "state", "==", "AZ")
or better yet
citiesRef.where("state == CA || state == AZ") Source: Firebase GIT
Solution 5:
For new users, who are watching this in 2021. the code is next: PS. there is no more "==" clause, it's now 'isEqualTo: parameter'
voidsetApplyStatus() {
var query = firebase.firestore().collection('applications');
query = query.where("jobSeekerId", isEqualTo: this.jobSeekerId)
query = query.where("jobId", isEqualTo: this.job.id)
query = query.get().then(querySnapshot => {
querySnapshot.forEach(doc => {
console.log(doc.data())
console.log('already exists')
this.applyStatus = true
})
})
}
Post a Comment for "Firestore Where Clause Doesn't Make The Condition."