使用Firestore的订单数据返回错误

时间:2018-03-18 15:09:04

标签: swift firebase google-cloud-firestore

我要阅读来自云端防火墙的帖子列表,但在尝试过滤和排序时,我收到了错误。

这很好,我得到了数据,但我还需要过滤掉年龄字段

database.collection("posts").whereField("isHidden", isEqualTo: false).order(by: "createdAt", descending: true).limit(to: 10).getDocuments{}

所以我尝试做类似的事情,但这会返回一个 - libc ++ abi.dylib:以NSException类型的未捕获异常终止错误

database.collection("posts").whereField("isHidden", isEqualTo: false).whereField("birthday", isGreaterThan: upperAgeDate)
                            .whereField("birthday", isLessThan: lowerAgeDate).order(by: "createdAt", descending: true).limit(to: 10).getDocuments{}

删除orderBy调用时它可以工作,但不是正确的解决方案

database.collection("posts").whereField("isHidden", isEqualTo: false).whereField("birthday", isGreaterThan: upperAgeDate)
                            .whereField("birthday", isLessThan: lowerAgeDate).limit(to: 10).getDocuments{}

这可能与firestore文档中的以下引用有关吗? “无效:范围过滤器和第一个订单在不同的字段上”

1 个答案:

答案 0 :(得分:0)

  

这可能与firestore文档中的以下引用有关吗? "无效:范围过滤器和第一个订单在不同的字段"

YES! documentation表示如果您的过滤器具有范围比较(<,< =,>,> =),则您的第一个排序必须位于同一个字段中。

您有birthday作为范围比较,createdAt作为订单