当 orderby 字符串值时,Flutter Firestore startAt() endtAt() 不起作用

Moz*_*ong 4 dart flutter google-cloud-firestore

我尝试在按标题排序时使用 startAt([1]) 和 endAt([3]) 但它不起作用。

QuerySnapshot snapshot = await Firestore.instance.collection('items')
  .orderBy("title", descending: false).startAt([1]).endAt([2]).limit(2).getDocuments();
Run Code Online (Sandbox Code Playgroud)

当我尝试按等级 startAt([1]) 和 endAt([3]) 排序时,它有效。

QuerySnapshot snapshot5 = await Firestore.instance.collection('items')
  .orderBy("rank", descending: false).startAt([1]).endAt([2]).limit(2).getDocuments();
Run Code Online (Sandbox Code Playgroud)

当我不使用 endAt() 时有效

为什么我按标题订购时不起作用?

QuerySnapshot snapshot = await Firestore.instance.collection('items')
  .orderBy("title", descending: false).startAt([1]).limit(2).getDocuments();
Run Code Online (Sandbox Code Playgroud)

有人有什么想法吗?

我尝试过: 1. 确保软件包是最新的 2. 在 firestore 上创建索引

[这不起作用] QuerySnapshot 快照 =等待 Firestore.instance.collection('items').orderBy("title", 降序: false).startAt([1]).endAt([2]).limit(2) .getDocuments();

[THIS WORKS]
QuerySnapshot snapshot5 = await Firestore.instance.collection('items')
  .orderBy("rank", descending: false).startAt([1]).endAt([2]).limit(2).getDocuments();

[THIS WORKS]
QuerySnapshot snapshot = await Firestore.instance.collection('items')
  .orderBy("title", descending: false).startAt([1]).limit(2).getDocuments();
Run Code Online (Sandbox Code Playgroud)

我期望的是在过滤时能够使用 endAt() 但它会抛出错误

Fra*_*len 5

我假设您的rank字段是数字,并且您的title字段是字符串。在这种情况下,这是预期的行为。

Firestore 查询按而不是偏移量进行过滤。所以当你:

.orderBy("rank", descending: false).startAt(1).endAt(2)
Run Code Online (Sandbox Code Playgroud)

文档按排名排序,然后返回排名在 1 到 2(含)之间的文档。

当你这样做时:

.orderBy("title", descending: false).startAt(1).endAt(2)
Run Code Online (Sandbox Code Playgroud)

文档按标题排序,然后返回标题在 1 和 2 之间的文档。但由于标题是字符串而不是数字,这意味着没有文档与条件匹配,并且不会返回任何内容。

Firestore 没有偏移查询的概念,您可以在其中告诉它跳过第一个n结果。