how to fetch documents from one month old only firestore

[亡魂溺海] 提交于 2020-06-09 05:48:09

问题


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

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

Query

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

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

any ideas?


回答1:


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.

You might want to read more about how server timestamps work with security rules at the end of this article.



来源:https://stackoverflow.com/questions/61124994/how-to-fetch-documents-from-one-month-old-only-firestore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!