【问题标题】:Unity Firestore Collection Snapshot - Document Amount Returning 0Unity Firestore 集合快照 - 返回 0 的文档数量
【发布时间】:2021-08-07 00:30:02
【问题描述】:

我有一个名为 CalendarEvents 的集合和两个文档,一个名为 08-01-2021,另一个名为 08-02-2021。这是我的代码:

firestore.Collection("CalendarEvents").GetSnapshotAsync().ContinueWithOnMainThread(task =>
    {

        QuerySnapshot snapshot = task.Result;
        IEnumerable<DocumentSnapshot> documents = snapshot.Documents;

        Debug.Log("Document Amount: " + documents.ToList().Count);

    });

打印到控制台的结果是0,我不知道为什么,因为有两个文档。我在这里有什么遗漏吗?

【问题讨论】:

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


【解决方案1】:

仔细检查集合名称是否正确、大小写正确且不包含隐藏空格" "

您也可以直接遍历文档而不是存储 IEnumerable 以确保文档在那里

firestore.Collection("CalendarEvents").GetSnapshotAsync().ContinueWithOnMainThread(task =>
{
  QuerySnapshot eventsQuerySnapshot = task.Result;
  foreach (DocumentSnapshot documentSnapshot in eventsQuerySnapshot .Documents)
  {
    Debug.Log(String.Format("Document data for {0} document:", documentSnapshot.Id));
    Dictionary<string, object> city = documentSnapshot.ToDictionary();
    foreach (KeyValuePair<string, object> pair in city)
    {
      Debug.Log(String.Format("{0}: {1}", pair.Key, pair.Value));
    }

    // Newline to separate entries
    Debug.Log("");
  }
});

如果您仍有问题,则很可能是被安全规则阻止了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-07
    • 1970-01-01
    • 1970-01-01
    • 2020-02-27
    • 1970-01-01
    • 2021-09-27
    • 2019-08-13
    • 2018-08-11
    相关资源
    最近更新 更多