Firestore中随机生成的文档ID的大小

huangapple go评论63阅读模式
英文:

Size of random autogenerated Document IDs in Firestore

问题

Firestore将文档限制为1MB,包括字段名称和文档ID。

根据我的测试,创建用户和文档的生成ID大约为50字节(我将数据建模在顶级集合中),但在文档中,它似乎可以高达1.5KB,这是一个巨大的差异。

这直接影响了我如何建模数据库,因为我有一个文档内的ID数组和一个计数器。我必须知道要存储多少个ID。

此外,用每个ID作为单个文档放在集合中来替代数组并不是一个合理的解决方案,这将花费太多。

我可以假设对于给定的集合,由于我的测试都给出了不到50B的ID范围,不会突然创建许多1.5KB的ID吗?

如果不假设这一点,文档内的数组中可以存储的ID数量从约2万个(如果每个ID大约有50B)降至只有660个(如果每个ID大约有1.5KB)。

Firebase不提供分析文档大小或自动生成的文档ID对于给定集合将有多少字节的方法。

我测试了许多不同的集合,并且已经有很多用户。所有这些自动生成的ID都不到50字节长,所以我假设这是一种模式,但由于文档中没有保证,我并不完全相信。

英文:

Firestore constrains Documents to 1MB, including field names and document IDs.

Well, as far as I've tested, the generated IDs for created users and documents were about 50 Bytes long(I'm modeling the data in top level collections), but in the documentation apparently it could be as high as 1.5KB, which is a huge difference.

This directly impacts how I model the database, since I have an array of IDs inside a document and a counter. I have to know how many IDs to store.

Also, replacing the array by a collection with each ID as a single document inside is not a reasonable solution, it'd cost too much.

Can I assume that for a given collection, since my tests are all giving the same range of less than 50B for IDs,it won't suddenly create many IDs with 1.5KB ?

Without assuming that, the amount of IDs I can store in the array inside a document goes from around 20 thousand (if each ID has around 50B) to as little as 660 (if each ID has around 1.5KB).

Firebase does not offer a way to analyse how big a document is nor how many bytes an autogenerated document ID will have for a given collection.

I tested many different collections and have many users already. All of those autogenerated IDs where less than 50 Bytes long, so I'm assuming this is a pattern, but not convinced about it since there is no guarantee from the documentation.

答案1

得分: 0

我可以假设对于给定的集合,由于我的测试都在提供小于50B的相同范围的ID,它不会突然创建很多1.5KB的ID吗?

Firebase没有提供一种分析文档大小或为给定集合生成自动生成文档ID的字节数的方法。

Firestore SDK始终生成相同长度的随机文档ID。它们不是由云服务生成的。如果你不信任这一点,你可以自己生成自己的ID,并使用set而不是add来添加文档。

参见:

你甚至可以查看源代码来自行验证这一点。这是一个链接到JavaScript源代码的链接,将长度限制在20个字符:

参见:

英文:

> Can I assume that for a given collection, since my tests are all giving the same range of less than 50B for IDs,it won't suddenly create many IDs with 1.5KB ?

> Firebase does not offer a way to analyse how big a document is nor how many bytes an autogenerated document ID will have for a given collection.

The Firestore SDKs always generate random document IDs of the same length. They are not generated by the cloud service. If you don't trust this, you can always generate your own IDs and add the document using set rather than add.

See:

You can even look at the source code to verify this yourself. Here's a link to JavaScript source that caps the length at 20 characters:

See:

huangapple
  • 本文由 发表于 2023年5月11日 07:08:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/76223132.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定