0

enter image description hereenter image description here

I have written code in my android studio which successfully stores images in firebase storage and its image download url in cloud firestore. Now, I want to get the ImageURL and BookName field values of all the nested Map.

How do write the query? I just started practicing firebase & firestore 1 week ago.

Note: I have created imageAdapter and recycleView. I just want to know the query to traverse through all nested field values and get the data of it.

Here is what I coded to get but i doesnt work...

noteRef.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
        @Override
        public void onComplete(@NonNull Task<QuerySnapshot> task) {
            if (task.isSuccessful()){
                for (QueryDocumentSnapshot documentSnapshot : task.getResult()){
                    UploadBookImage uploadBookImage = documentSnapshot.toObject(UploadBookImage.class);
                    mUploads.add(uploadBookImage);
                }
                mAdapter = new ImageAdapter(getActivity(), mUploads);
                mRecycleView.setAdapter(mAdapter);
            }
        }
    });



Modal class
package com.example.takeit;

public class UploadBookImage {
private String mBookName, mImageUrl, mBookEdition, mBookYear, mBookSem;

public UploadBookImage(){
    //empty constructor..
}

public UploadBookImage(String name, String imageUrl, String edition, String year, String sem){
    mBookName = name;
    mImageUrl = imageUrl;
    mBookEdition = edition;
    mBookYear = year;
    mBookSem = sem;
}

public String getName(){
    return mBookName;
}
public void setName(String name){
    mBookName = name;
}

public String getImageUrl(){
    return mImageUrl;
}
public void setImageUrl(String imageUrl){
    mImageUrl = imageUrl;
}

public String getEdition(){
    return mBookEdition;
}
public void setEdition(String edition){
    mBookEdition = edition;
}

public String getYear(){
    return mBookYear;
}
public void setYear(String year){
    mBookYear = year;
}

public String getSem(){
    return mBookSem;
}
public void setSem(String sem){
    mBookSem = sem;
}

}

Rohan Patel
  • 31
  • 1
  • 8
  • 1
    There are many questions mentioning [`[google-cloud-firestore][android] nested field`](https://stackoverflow.com/search?q=%5Bgoogle-cloud-firestore%5D%5Bandroid%5D+nested+field) already. What have you tried? – Frank van Puffelen Jul 19 '20 at 16:11
  • It would be a good idea if you edit the question to show the code you have so far, and explain what isn't working the way you expect. Point out specifically where you are stuck. – Doug Stevenson Jul 19 '20 at 16:33
  • @DougStevenson i just want to know how to query the nested field so I can get the data in it?? – Rohan Patel Jul 19 '20 at 16:44
  • @DougStevenson for (DataSnapshot postSnapshot : dataSnapshot.getChildren()){ UploadBookImage uploadBookImage = postSnapshot.getValue(UploadBookImage.class); mUploads.add(uploadBookImage); } mAdapter = new ImageAdapter(getActivity(), mUploads); mRecycleView.setAdapter(mAdapter); Like this is how query through all the Firebase database field but now I want to get it for Firestore.. – Rohan Patel Jul 19 '20 at 16:46
  • I suggest **editing the question** to include extra information. Use the edit link at the bottom of the question - don't add new comments. – Doug Stevenson Jul 19 '20 at 16:49
  • This depends on what your UploadBookImage class looks like. Please edit the question to show it, and explain how you expect the map fields to end up in that object. – Doug Stevenson Jul 19 '20 at 17:54
  • The problem lies in the fact that the names of the properties in the database do **not** match the one in your class. – Alex Mamo Jul 20 '20 at 07:11

0 Answers0