So I'm using firestore to store data about ingredients and I've been able to add, delete, and get all the items in the database but I can't figure out search and get a single document snapshot. I feel like the code should work so I'm lost.
This is what I tried
public Ingredient searchForIngredient(String ingredient) {
Log.d(TAG,ingredient);
ArrayList<Ingredient> retrieved = new ArrayList<Ingredient>();
ingredientsDB.document(ingredient).addSnapshotListener(new EventListener<DocumentSnapshot>() {
@Override
public void onEvent(@Nullable DocumentSnapshot value, @Nullable FirebaseFirestoreException error) {
Log.d(TAG, "on event");
Ingredient ingredient = createIngredient(value);
retrieved.add(ingredient);
}
});
Ingredient ingredient1 = retrieved.get(0);
return ingredient1;
}
And what I was expecting is for the "on even" to show up in logcat but it doesn't