【问题标题】:How to fetch values from Firestore with where() followed by startAt() and endAt()如何使用 where() 后跟 startAt() 和 endAt() 从 Firestore 获取值
【发布时间】:2019-06-14 09:44:30
【问题描述】:

我正在使用 anguarfire2,我只需要从 Firestore 中获取来自特定类型客户的值并按职位排序

我已经尝试了以下但没有给我任何结果

angularFirestore.collection('customers', ref => ref.where('type', '==', type)
            .orderBy('position')
            .startAt(1)
            .endAt(2))

但是

   angularFirestore.collection('customers', ref => ref.orderBy('position')
            .startAt(1)
            .endAt(2) )

它有效。无论客户类型如何,它都能为我提供结果。

是否可以通过 where、orderBy、startAt 和 endAt 的组合来获取值?

【问题讨论】:

  • 您需要将多个 where 与要过滤的每个子句链接起来

标签: javascript google-cloud-firestore angularfire2


【解决方案1】:

您不需要对这里文档中提到的查询进行分页enter link description here

你也可以参考下面的代码来达到同样的效果:

let first = db.collection('cities')
           .orderBy('population')
           .limit(3);

let paginate = first.get()
.then((snapshot) => {
// ...

// Get the last document
let last = snapshot.docs[snapshot.docs.length - 1];

// Construct a new query starting at this document.
// Note: this will not have the desired effect if multiple
// cities have the exact same population value.
let next = db.collection('cities')
  .orderBy('population')
  .startAfter(last.data().population)
  .limit(3);

// Use the query for pagination
// ...

});

【讨论】:

    猜你喜欢
    • 2018-08-19
    • 1970-01-01
    • 2020-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多