Skip to content

Commit

Permalink
Remove unnecessary Exists checks.
Browse files Browse the repository at this point in the history
A QuerySnapshot only consists of existing documents, so there's no need to check DocumentSnapshot.Exists.
  • Loading branch information
Michael Lehenbauer committed Aug 16, 2019
1 parent 81697f2 commit a154ba2
Showing 1 changed file with 10 additions and 24 deletions.
34 changes: 10 additions & 24 deletions firestore/api/GetData/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,20 +154,13 @@ private static async Task GetMultipleDocs(string project)
QuerySnapshot capitalQuerySnapshot = await capitalQuery.GetSnapshotAsync();
foreach (DocumentSnapshot documentSnapshot in capitalQuerySnapshot.Documents)
{
if (documentSnapshot.Exists)
{
Console.WriteLine("Document data for {0} document:", documentSnapshot.Id);
Dictionary<string, object> city = documentSnapshot.ToDictionary();
foreach (KeyValuePair<string, object> pair in city)
{
Console.WriteLine("{0}: {1}", pair.Key, pair.Value);
}
Console.WriteLine("");
}
else
Console.WriteLine("Document data for {0} document:", documentSnapshot.Id);
Dictionary<string, object> city = documentSnapshot.ToDictionary();
foreach (KeyValuePair<string, object> pair in city)
{
Console.WriteLine("Document {0} does not exist!", documentSnapshot.Id);
Console.WriteLine("{0}: {1}", pair.Key, pair.Value);
}
Console.WriteLine("");
}
// [END fs_get_multiple_docs]
}
Expand All @@ -180,20 +173,13 @@ private static async Task GetAllDocs(string project)
QuerySnapshot allCitiesQuerySnapshot = await allCitiesQuery.GetSnapshotAsync();
foreach (DocumentSnapshot documentSnapshot in allCitiesQuerySnapshot.Documents)
{
if (documentSnapshot.Exists)
{
Console.WriteLine("Document data for {0} document:", documentSnapshot.Id);
Dictionary<string, object> city = documentSnapshot.ToDictionary();
foreach (KeyValuePair<string, object> pair in city)
{
Console.WriteLine("{0}: {1}", pair.Key, pair.Value);
}
Console.WriteLine("");
}
else
Console.WriteLine("Document data for {0} document:", documentSnapshot.Id);
Dictionary<string, object> city = documentSnapshot.ToDictionary();
foreach (KeyValuePair<string, object> pair in city)
{
Console.WriteLine("Document {0} does not exist!", documentSnapshot.Id);
Console.WriteLine("{0}: {1}", pair.Key, pair.Value);
}
Console.WriteLine("");
}
// [END fs_get_all_docs]
}
Expand Down

0 comments on commit a154ba2

Please sign in to comment.