Im new to Firebase, currently have a Real time firebase database, im trying to add a "WHERE" clause to the code that returns data. I need to return all rows that have UserId = userId.
I have tried -
firebaseClient.Child("MapPins/UserId/" userId)
and
firebaseClient.Child("MapPins")
.Child("UserId")
.Child(userId)
The code below currently returns all pins, regardless of the userid field.
public async Task<ObservableCollection<MapPinModel>> GetPinsForUserFirebase(string userId)
{
ObservableCollection<MapPinModel> mapView = new ObservableCollection<MapPinModel>();
try
{
var collection = firebaseClient.Child("MapPins")
.AsObservable<MapPinModel>()
.Subscribe((dbevent) =>
{
if (dbevent.Object != null)
{
mapView.Add(dbevent.Object);
}
});
}
catch (Exception ex)
{
}
return mapView;
}
Here is the data structure
CodePudding user response:
It's hard to be certain without seeing your data structure, but I think you're looking for:
firebaseClient.Child("MapPins")
.OrderBy("UserId")
.EqualTo(userId)
...