简体   繁体   English

Collection Listener 的 Firestore 计费

[英]Firestore billing for Collection Listener

I want to add a listener to my collection to trigger a function "getNewChats()" whenever a document is added to the collection.我想在我的集合中添加一个侦听器,以便在将文档添加到集合时触发 function“getNewChats()”。

I have the following listener in my initState:我的 initState 中有以下侦听器:

 CollectionReference reference = Firestore.instance.collection('chats');

  @override
  void initState() {
    super.initState();
    getChats();

    reference.snapshots().listen((querySnapshot) {
      querySnapshot.documentChanges.forEach((change) {
        getNewChats();
      });
    });

My question is whether I will be charged for reading every document in the "chats" collection every time the init state is run or will I only be charged when there is a change in the collection like a document added?我的问题是,每次运行 init state 时,我是否会因阅读“聊天”集合中的每个文档而被收费,或者只有当集合中发生变化(如添加文档)时我才会被收费?

If so, is there any way to only listen to the most recently added document so I'm not reading everything?如果是这样,有没有办法只听最近添加的文档,这样我就不会阅读所有内容?

On the first invocation of the listener, you will be billed 1 read for each document in the collection.在第一次调用侦听器时,您将为集合中的每个文档支付 1 次阅读费用。 After that, for each document added or modified, you will be billed for that document, until the listener is removed.之后,对于添加或修改的每个文档,您都需要为该文档付费,直到删除监听器。

If you don't want to read all the documents in the colleciton, you will need a filter on that document.如果您不想阅读集合中的所有文档,则需要对该文档进行过滤。 If you want only documents after a certain point in time, you will need to add a timestamp field to each document, and filter on that field.如果您只想要某个时间点之后的文档,则需要为每个文档添加一个时间戳字段,并在该字段上进行过滤。 Your all will need to know what timestamp to use for the query - Firestore will not keep track of that for you.您都需要知道用于查询的时间戳 - Firestore 不会为您跟踪。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM