且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 Swift 中从 Cloud FireStore Firebase 访问特定字段

更新时间:2022-12-22 18:46:21

没有任何 API 可以使用任何 Web 或移动客户端 SDK 从文档中提取单个字段.当您使用 getDocument() 时,始终会获取整个文档.这意味着也无法使用安全规则来保护文档中的单个字段与其他字段不同.

There is no API that fetches just a single field from a document with any of the web or mobile client SDKs. Entire documents are always fetched when you use getDocument(). This implies that there is also no way to use security rules to protect a single field in a document differently than the others.

如果您想尽量减少通过网络传输的数据量,您可以将该单独的字段放在主文档的子集合中的自己的文档中,并且您可以单独请求该文档.

If you are trying to minimize the amount of data that comes across the wire, you can put that lone field in its own document in a subcollection of the main doc, and you can request that one document individually.

另请参阅此讨论主题.

服务器 SDK 可以使用诸如 select() 之类的方法,但您显然需要在后端编写代码并从您的客户端应用程序调用它.

It is possible with server SDKs using methods like select(), but you would obviously need to be writing code on a backend and calling that from your client app.