I'm using Firebase Cloud Firestore
, I want when I'm getting a document with reference field inside to receive the reference field as a document and not as a reference to the document...
I have a collection of users and collection of classes (at school) and each class contains a list of references to users (the students in this class).
When I using document.get()
(to get the class by its reference) it returns an object that contains a list of DocumentReference
(of the users) so I need to call document.get()
around 20 more times just to get the users as objects and not as a reference to them.
I want to be able to call document.get()
once and it will bring me all the references as documents, like that:
database and code
Is there an elegant way to do this?
A DocumentReference refers to a document location in a Firestore database and can be used to write, read, or listen to the location. The document at the referenced location may or may not exist. A DocumentReference can also be used to create a CollectionReference to a subcollection.
CollectionReference collectionReference = FirebaseFirestore. getInstance(). collection("public_messages"); ArrayList<String> ids = new ArrayList<>(); //Contains your keys ArrayList<Task<QuerySnapshot>> tasks = new ArrayList<>(); for (String id : ids) { Task<QuerySnapshot> task = collectionReference.
New document with same ID should not be allowed in the same collection. It should be possible to fetch an already existing document from a previous import.
DocumentReference docRef = FirebaseFirestore. instance. doc("cards/WzU..."); and then use the get() method on this DocumentReference .
You can't instruct the Firestore client SDK to automatically follow document references during a fetch of a single document. You have to request each individual document. In other words, there is no "join" operation like you might expect in SQL.
See also: What is firestore Reference data type good for?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With