Reputation: 2811
I am trying to count the array which is contained in a collection. The data is structured like this:
{requests=[{name=Jayson, created=1599139605672, from=jayson123, to=marco123, timestamp=2020-09-03T13:26:45+00:00}]}
In the example above I would like to count how many arrays does the requests
collection contains, which in that case is 1.
I am using snapshot.getData().size()
but it is always returning 1. Can you help me pls.
Upvotes: 0
Views: 97
Reputation: 317808
If you want to know the size of a list type field in a document, you have to:
size()
method on that List.It will be something like this, assuming you have a snapshot:
DocumentSnapshot snapshot = ...
List<Object> requests = (List<Object>) snapshot.get("requests");
int size = requests.size();
Upvotes: 1