Firestore where 子句不构成条件。

Dul*_*age 2 javascript firebase vue.js google-cloud-firestore

在我的函数中,我有两个 where 子句。我想要的是检查文档是否存在,在那里找到两个 id。但是当我运行它时,它会返回所有收集记录。谁能告诉我我哪里搞砸了?

setApplyStatus() {
   var query = firebase.firestore().collection('applications')
   query.where("jobSeekerId", '==', this.jobSeekerId).get()
   query.where("jobId", '==', this.job.id)
   query.get().then(querySnapshot => {
    querySnapshot.forEach(doc => {
     console.log(doc.data())
     console.log('already exists')
     this.applyStatus = true
    })
   })
 }
Run Code Online (Sandbox Code Playgroud)

Dou*_*son 8

您没有正确链接查询子句。此外,您在链的中间调用 get() 。这几乎肯定不是你想要的。每个查询对象都建立在最后一个之上,并且您应该只在链中的最终查询上使用 get() :

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
    })
  })
}
Run Code Online (Sandbox Code Playgroud)