How to map an array of objects from Cloud Firestore to a List of objects?

Alex Mamo
Firebase Tips & Tricks
2 min readMar 25, 2020

--

User objects from Array moved into User object in a List

Even from the beginning, the array is a supported data type in Cloud Firestore. It’s very useful for storing data in String format or even as custom objects, as long as the size of the document is less than 1 MiB (1,048,576 bytes). For larger amounts of data, a sub-collection is more likely to be used. However, if we only need small datasets, then storing data in an array is the best option.

Now, let’s assume we have a document that contains a property of type array. This array is named users and holds a few User objects. The User class is very simple, contains only two properties, and looks like this:

And this is the database structure:

A collection of applications, a random document, and an array

So our goal is to get in code the users array as a List<User>. To achieve that, we need to attach a listener on the document and use a get() call:

--

--