如果Firestore数据库发生更改,我是否要再次阅读所有文档? [英] Do I read all documents again if there is a change in the Firestore database?

查看:36
本文介绍了如果Firestore数据库发生更改,我是否要再次阅读所有文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我说我尝试使用Firestore侦听器获取用户喜欢的eventID列表.我还使用离线持久性.

let say I try to get a list of eventID that liked by the user by using Firestore listener. I also use offline persistence.

从此线程: Firestore-使用缓存直到在线内容更新

我知道,缓存中的结果将立即触发侦听器,如果有更改结果,我将获得包含更改的另一个快照.

I know that the listener will be fired immediately with the results from the cache and if there is a change result, I will get another snapshot with the changes.

快速获取列表的参考是:

in swift, the reference to get the list is:

FirestoreDocumentReference.users(uidUser: uid).reference().collection("likedEvents").addSnapshotListener({ (snapshot, error) in )}

首先要说的是,在Firestore数据库中,我有100个用户喜欢的eventID,然后用户又喜欢了另一个50个事件,这意味着我现在在数据库中有150个喜欢的eventID.

let say at first in the firestore database I have 100 eventID that liked by the user, and then the user like another 50 event, it means I have 150 liked eventID in the database now.

由于数据库从100更改为150,Firestore会与服务器核对吗?这会给我另一个快照.

since there is a change in the database from 100 to 150, Firestore will check with the server right? and it will give me another snapshot.

我的问题是....

从Firestore接收新快照后,我阅读150个文档还是仅阅读50个文档?我的意思是,我要重新阅读所有文档还是只是更改文档?

Do I read 150 documents or just 50 documents after receiving new snapshot from firestore? I mean, Do I read all documents again or just changed document?

因为读取操作会影响Firestore的价格

because read operation will affect the pricing of firestore

推荐答案

只需50岁:-)
https://firebase.google.com/docs/firestore/pricing#listens

Just 50 :-)
https://firebase.google.com/docs/firestore/pricing#listens

每次添加或更新结果集中的文档时,您都要付费阅读

you are charged for a read each time a document in the result set is added or updated

这篇关于如果Firestore数据库发生更改,我是否要再次阅读所有文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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