【问题标题】:How do I use FirestoreProperty with DocumentReference?如何将 FirestoreProperty 与 DocumentReference 结合使用?
【发布时间】:2021-04-09 05:10:42
【问题描述】:

我在 Unity 应用程序中使用 Firestore。我在文档上有一个字段作为类型参考。当尝试为此数据创建自定义对象类时(如此处所示https://firebase.google.com/docs/firestore/manage-data/add-data#custom_objects),我无法使用 ConvertTo 创建 documentReference。

数据类

[FirestoreData]
public class LeaderboardItem
{
    [FirestoreProperty]
    public int Score { get; set; }
    
    [FirestoreProperty]
    public DocumentReference ScoreRef { get; set; }
}

尝试转换成自己的对象

documentSnapshot.ConvertTo<LeaderboardItem>();

【问题讨论】:

  • 我现在没有很好的答案,但权宜之计的答案是 Firestore 通常不能将文档存储在其他文档中(它总是交错收集集合->文档->集合->文档)。您可能最好暂时在此处存储一个字符串并手动将其扩展为新的文档参考。也可以在github.com/firebase/quickstart-unity/issues 上提问
  • 如果您(或其他任何人)仍然遇到此问题,我们希望您打开一个错误 ???? github.com/firebase/quickstart-unity/issues
  • 您在尝试转换时是否遇到错误?我还发现这个answer 与您的问题类似,可能会有所帮助。

标签: c# firebase unity3d google-cloud-firestore


【解决方案1】:

您在字符串或 DocumentReference 属性上使用 FirestoreDocumentId 属性,对于字符串,您将获得文档 ID,对于 DocumentReferance,您将获得文档引用。

【讨论】:

  • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center。
猜你喜欢
  • 1970-01-01
  • 2021-12-11
  • 2012-04-01
  • 2017-06-13
  • 2019-02-09
  • 2012-08-21
  • 2018-02-23
  • 2017-02-10
  • 2023-03-08
相关资源
最近更新 更多