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

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

问题描述

以下是我的数据结构:

我有一个试图从Cloud Firestore访问数据的ios应用程序。我成功地检索了完整的文档并查询了文档。但是,我需要访问特定文档中的特定字段。我如何拨打电话,从swift中的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只从文档中提取单个字段。使用 getDocument时,始终会提取整个文档( )。这意味着也无法使用安全规则来保护文档中的单个字段与其他字段不同。

There is no API that fetches just a single field from a document. 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.

参见讨论主题

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

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