问题描述
我得到了一个集合 users/$ userID/followers
,该用户ID是Firebase UID,所以长29个字节(字符串大小是按UTF-8编码字节数+ 1来计算的.)
I got a collection users/$userID/followers
this user ID is the firebase UID so is 29 bytes long ( String sizes are calculated as the number of UTF-8 encoded bytes + 1.)
在每个用户文档中,我都有一个名为followers的数组和另一个名为followings的数组.这两个数组都包含很多userID,所以这就是问题所在.
Inside each user document i got a array named followers and another named following. Both arrays contain a lot of userID's so here's the problem.
在Firestore中,每个文档的最大大小为1mb,因此很容易看到我很快就会用完空间.我的问题是管理这样的大型阵列的最佳方法是什么.
In firestore each document has a max size of 1mb so it's easy to see I'm gonna run out of space soon. My question is what's the best way to manage large arrays like this ones.
最明显的选择:创建另一个文档,该文档仅包含一对新数组以继续保存该数据(并在达到文档限制时以递归方式执行此操作).
Most obvious option: Create another document, containing just a pair of new arrays to continue saving this data ( and do this in a recursive way when the limit of the document is reached).
那么有更好的主意吗?或者至少是如何简化流程.
So some better idea? Or at least how to simplify the process a little bit.
有关尺寸限制的更多信息,请点击此处: https://firebase.google.com/docs/firestore/storage-size?hl = zh-419
More info about size limits here:https://firebase.google.com/docs/firestore/storage-size?hl=en-419
推荐答案
如果您担心数组的大小,则应该将每个项目从数组中拆分出来,并使其成为自己的文档.这是使用Firestore来存储大量单个项目的大规模扩展性的唯一方法.
If you're concerned about the size of an array, you should instead split each item out of the array and make it its own document. This is the only way you will achieve massive scalability with Firestore for storing many individual items.
是的,它将花费更多.可伸缩性是有代价的.
Yes, it will cost more. There is a cost to scalability.
这篇关于Firestore存储大小限制了如何存储大型阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!