简体   繁体   中英

Filter Firebase Children By Value Xamarin.Forms

I have the below hierarchy in my firebase realtime databse, I want to get all children with specific value of the "status" child. How can I do that? Thanks in advance

Firebase Hierarchy

You need to add

First open database ;

FirestoreDbBuilder builder = new FirestoreDbBuilder();
    //I am reading configs from json
      using (var stream = new StreamReader(@"appsettings.json"))
           {
              var obj = JObject.Parse(stream.ReadToEnd());
              var test = obj.SelectToken("AuthTokenOptions");
              builder.JsonCredentials = test.ToString();
              builder.ProjectId = "projectId";
              firestoreDb = builder.Build();
            }
    
    collection = firestoreDb.Collection(_collectionName);

Then you need to Query with your status Column

Query _query = collection.WhereEqualTo("status", "reserved");
QuerySnapshot allQuerySnapshot = await _query .GetSnapshotAsync(token);

 List<TEntity> entities = new List<TEntity>();

            if (allQuerySnapshot.Count > 0)
                foreach (DocumentSnapshot documentSnapshot in allQuerySnapshot.Documents)
                {
                    entities.Add(documentSnapshot.ConvertTo<TEntity>());
                };

            return entities;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM