如何从一个月大的firestore中获取文档 [英] how to fetch documents from one month old only firestore

查看:75
本文介绍了如何从一个月大的firestore中获取文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查询仅获取1个月大的文档.

I'm doing a query to fetch only 1 month old documents.

我存储文档本身的创建时间

I store the creation time of the document itself

timestamp : 9 Apr, 2020 10:03:43 AM

现在,在查询中,我想获取当月的所有文档,但我不想从客户端使用currentDate(因此无法更改),但是我也不想查询该文档以查找时间戳记该文件的

Now, in my query , I want to get all the documents whithin the current month but I dont want to use currentDate from my client (so it cannot be changed) but also I dont want to query that document to find the timestamps of that document

查询

FirebaseFirestore.getInstance().collection("orders").whereEqualTo("shopId",shopId)
                .whereEqualTo("status", 7).startAt().endAt().get().await()

我想知道一个有效的服务器代理设置为.startAt().endAt(),以便仅查询状态为7且过去1个月的文档

I want to know an efficient server aproximation to set at .startAt().endAt() to query just the documents with status 7 in which has past 1 month

有什么想法吗?

推荐答案

Firestore不提供基于时间的查询,这些查询会根据服务器时间来限制文档范围.您将必须相信客户端发送的时间正确.

Firestore does not offer timeboxed queries that restrict a range of documents based on the sense of server time. You will have to trust that the client is sending the correct time.

随着时间的推移,您唯一的控制权就是使用请求.时间规则.您可以编写一条规则,以允许查询仅落在基于服务器时间戳记的时间内,但是由客户端来决定是否在查询中正确指定时间仍由您自己决定.规则将无法根据时间过滤结果.

The only control you have over time is using request.time in security rules. You could write a rule to allow queries that only fall within times based on the server timestamp, but it's still up to the client to specify the time correctly in the query. The rules will not be able to filter results based on time.

您可能想在 查看全文

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