Beispiel #1
0
 public void Equality_CollectionGroup()
 {
     EqualityTester.AssertEqual(s_db.CollectionGroup("col"),
                                equal: new[] { s_db.CollectionGroup("col") },
                                unequal: new[] { s_db.Collection("col") }
                                );
 }
        private static async Task CollectionGroupQuery(string project)
        {
            FirestoreDb         db        = FirestoreDb.Create(project);
            CollectionReference citiesRef = db.Collection("cities");
            // [START fs_collection_group_query_data_setup]
            await citiesRef.Document("SF").Collection("landmarks").Document()
            .CreateAsync(new { Name = "Golden Gate Bridge", Type = "bridge" });

            await citiesRef.Document("SF").Collection("landmarks").Document()
            .CreateAsync(new { Name = "Legion of Honor", Type = "museum" });

            await citiesRef.Document("LA").Collection("landmarks").Document()
            .CreateAsync(new { Name = "Griffith Park", Type = "park" });

            await citiesRef.Document("DC").Collection("landmarks").Document()
            .CreateAsync(new { Name = "Lincoln Memorial", Type = "memorial" });

            await citiesRef.Document("DC").Collection("landmarks").Document()
            .CreateAsync(new { Name = "National Air And Space Museum", Type = "museum" });

            await citiesRef.Document("TOK").Collection("landmarks").Document()
            .CreateAsync(new { Name = "Ueno Park", Type = "park" });

            await citiesRef.Document("TOK").Collection("landmarks").Document()
            .CreateAsync(new { Name = "National Museum of Nature and Science", Type = "museum" });

            await citiesRef.Document("BJ").Collection("landmarks").Document()
            .CreateAsync(new { Name = "Jingshan Park", Type = "park" });

            await citiesRef.Document("BJ").Collection("landmarks").Document()
            .CreateAsync(new { Name = "Beijing Ancient Observatory", Type = "museum" });

            // [END fs_collection_group_query_data_setup]

            // [START fs_collection_group_query]
            Query         museums       = db.CollectionGroup("landmarks").WhereEqualTo("Type", "museum");
            QuerySnapshot querySnapshot = await museums.GetSnapshotAsync();

            foreach (DocumentSnapshot document in querySnapshot.Documents)
            {
                Console.WriteLine($"{document.Reference.Path}: {document.GetValue<string>("Name")}");
            }
            // [END fs_collection_group_query]
        }