如何在 Swift 中从 Cloud FireStore Firebase 访问特定字段 [英] How to access a specific field from Cloud FireStore Firebase in Swift

查看:23
本文介绍了如何在 Swift 中从 Cloud FireStore Firebase 访问特定字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的数据结构:

我有一个 ios 应用程序试图从 Cloud Firestore 访问数据.我已成功检索完整文档和查询文档.但是,我需要访问特定文档中的特定字段.我将如何进行调用以快速从 Firestore 中检索一个字段的值?任何帮助,将不胜感激.

I have an ios app that is attempting to access data from Cloud Firestore. I have been successful in retrieving full documents and querying for documents. However I need to access specific fields from specific documents. How would I make a call that retrieves me just the value of one field from Firestore in swift? Any Help would be appreciated.

推荐答案

没有任何 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.

这篇关于如何在 Swift 中从 Cloud FireStore Firebase 访问特定字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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