Google CloudFirestore中的多个where子句

时间:2018-04-17 05:59:35

标签: google-cloud-datastore google-cloud-firestore angular2-services

我在Angular 4中,我需要用多个where子句组成一个查询。这是我的代码如下。 如何将多个where子句添加到queryfn中?

this.db.collection('cities', x => x.where('city', '==', 'CA'))
      .snapshotChanges()

谢谢

1 个答案:

答案 0 :(得分:0)

正如您在this related question所看到的那样,可以将您的子句链接或附加到查询引用:

// option 1
const ref = admin.firestore().collection('collectionName')
const query = ref.where('foo', '==', 'bar').where('baz', ==, 'buz')

query.get()
  .then(snapshot => {
    snapshot.forEach(res => console.log(res.data())
  })

// option 2
const ref = admin.firestore().collection('collectionName')
const query = ref.where('foo', '==', 'bar')
query.where('biz', <=, 5)
query.where('zaz', ==, 9)

query.get()
  .then(snapshot => {
    snapshot.forEach(res => console.log(res.data())
  })