I have the following structure of my Firestore database:
products:{ // Collection
procuct_1: { // Document
title:"",
url:""
videos:{ // Collection
video_1:{ // Document
title:"",
products:{ // Array of references
0: "/products/product_1,
1: "/products/product_2
I would like to be able from Array field in Videos Collection to get Document References to Products collection in order to get values of some fields of this collection (ex. title of product).
For the moment I use this code:
FirebaseFirestore firebaseFirestore = FirebaseFirestore.getInstance();
firebaseFirestore
.collection("videos")
.get()
.addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
DocumentSnapshot documentSnapshot = task.getResult();
Map<String, Object> map = documentSnapshot.getData();
for (Map.Entry<String, Object> entry: map.entrySet()){
if (entry.getKey().equals("products")){
textView.setText(entry.getValue().toString());
}
}
But entry.getValue().toString(), returns me such array:
[com.google.firebase.firestore.DocumentReference@451d5ae8,
com.google.firebase.firestore.DocumentReference@e28cd0c]
Any suggestions how I can get any field of Product collection from this Array?