Reputation: 361
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
Upvotes: 0
Views: 141
Reputation: 146
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;
Upvotes: 1