Firestore是否支持跳过功能? [英] Does firestore support skip functionality?

查看:72
本文介绍了Firestore是否支持跳过功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

摘要:我想使用MySql和MongoDb中使用的'skip'函数.但是,"startAfter(number)"不会跳过.

Summary: I want to use the 'skip' function used in MySql and MongoDb. However, 'startAfter (number)' does not skip.

我现在正在制作公告栏.然后我有一个问题.

I am making a bulletin board now. Then I got a question.

这是跳页的问题.

我使用将页面直接移至用户的基本方法.

I use the basic method of moving pages directly to users.

但是,我找不到Mysql或MongoDB过去使用的任何跳过函数.

However, I could not find any skip functions that Mysql or MongoDB used in the past.

这是我的代码的一部分.

This is part of my code.

return db.collection('boards').doc(title).collection('posts')
.orderBy('date').startAfter(2).limit(10).get()

所以我想从按日期排序的数据中跳过两个数据.

So I want to skip two data from the data sorted by date.

但是,'startAfter'中的任何数字都将从第一个数据中获取.

However, any number in 'startAfter' will be taken from the first data.

我当然在官方文档中检查了以下代码.

Of course, I checked the following code in the official document.

return first.get().then(function (documentSnapshots) {
  // Get the last visible document
  var lastVisible = documentSnapshots.docs[documentSnapshots.docs.length-1];
  console.log("last", lastVisible);

  // Construct a new query starting at this document,
  // get the next 25 cities.
  var next = db.collection("cities")
          .orderBy("population")
          .startAfter(lastVisible)
          .limit(25);
});

但是,上述方法非常麻烦,因为可能无条件拥有现有数据.

However, the above method is very troublesome because it is possible to have existing data unconditionally.

这不是一个好方法吗?我正在等待回复.

Is not there a good way? I am waiting for a reply.

推荐答案

客户端SDK

此文档说明:

fieldValuesOrDocumentSnapshot

(可重复使用任何类型或DocumentSnapshot)

查询结果应从其后开始的文档的快照或从其开始的字段值,以查询的顺序为基础.

The snapshot of the document the query results should start after or the field values to start this query after, in order of the query's order by.

因此,您不能简单地指定要跳过的文档数.您将需要从第二个文档中了解一个值(ID,字段值等),或者获取前两个文档,然后使用第二个文档的快照来生成查询.

Therefore, you are unable to simply specify the number of documents to skip. You will either need to know a value from that second document (ID, field value, etc.) or get the first 2 documents, then use the snapshot of the second document, to generate your query.

使用Admin SDK,存在偏移方法,该方法应该可以使您实现所需的目标.

With the Admin SDK, there is the offset method, which should allow you to achieve what you are looking for.

这篇关于Firestore是否支持跳过功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆