I’m new on Firebase Firestore and I trying to check if certain document exist on my database, but my boolean always return false. I’m using C# with Unity and Firebase v9.3.0.
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;
});
}
Here a image of my database data with respective id I’m searching:
I tried to change the code to use Async/Await operators, despite my Unity not showing any log error, my Visual Studio returns CS1061 exception (Task does not have a definition to “GetAwaiter”)
Here my Async/Await code:
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}");
}
I don’t know what could be going on, if anyone can help me, I would be immensely grateful.
Enrisco:
I’m new on Firebase Firestore and I trying to check if certain document exist on my database, but my boolean always return false. I’m using C# with Unity and Firebase v9.3.0.
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;
});
}
Here a image of my database data with respective id I’m searching:
I tried to change the code to use Async/Await operators, despite my Unity not showing any log error, my Visual Studio returns CS1061 exception (Task does not have a definition to “GetAwaiter”)
Here my Async/Await code:
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}");
}
I don’t know what could be going on, if anyone can help me, I would be immensely grateful.
Try:
FirebaseFirestore _firestore = FirebaseFirestore.DefaultInstance;
void CheckIfUserAreRegistered()
{
_firestore.Document($"Users/{FacebookManager.UserID}").GetSnapshotAsync().ContinueWith(task =>
{
if (task.Result.Exists) Debug.Log("Exists");
else Debug.Log("No Exists");
});
}
have you ever find a solution for this, bec I’ve the same problem