You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Firestore中Task<DocumentSnapshot>.Result.Exists始终返回false问题求助

Unity中Firebase Firestore检测文档存在始终返回false的问题

我是Firebase Firestore新手,在Unity中使用C#(Firebase v9.3.0)检测数据库中指定文档是否存在时,Exists布尔值始终返回false。数据库中确实存在对应ID的文档,但不知道问题出在哪,恳请帮助。

初始代码

public static void CheckIfUserAreRegistered()
{
    DocumentReference doc = Database.Collection("Users").Document(FacebookManager.UserID);

    doc.GetSnapshotAsync().ContinueWithOnMainThread(task =>
    {
        if (task.Result.Exists) UserAreRegistered = DefaultState.Yes;
        else UserAreRegistered = DefaultState.No;
    });

}

编辑补充

我尝试改用Async/Await操作符,Unity未显示日志错误,但Visual Studio报CS1061异常(Task没有“GetAwaiter”定义)。

Async/Await代码

public static async Task<DocumentSnapshot> WaitForCheckUsers()
{
    DocumentReference doc = Database.Collection("Users").Document(FacebookManager.UserID);

    return await doc.GetSnapshotAsync();
}

public static async void CheckIfUserAreRegistered()
{
    DocumentSnapshot doc = await WaitForCheckUsers();
    if (doc.Exists) UserAreRegistered = DefaultState.Yes;
    else UserAreRegistered = DefaultState.No;
    Debug.Log($"bool: {doc.Exists} UserID: {FacebookManager.UserID} Doc: {doc.Id}");
}

内容的提问来源于stack exchange,提问作者Enrisco

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 23:30:57