How to fetch documents from subcollection using spring FirestoreReactiveRepository?
Ask is: how subcollection name or path can be given dynamically to @Document annotation?
My firestore collection: (cities is first level collection and apartments is subcollection of this)
cities - nyc (id)- |- name: New York City
|- country: USA
└ apartments - part_avenue (document id)
├ name: Park Avenue
└ zip: 10022
- plaza (document id)
├ name: Plaza Riverhouse
└ zip: 10132
City POJO is
@Document(collectionName = "cities")
public class City {
@DocumentId
private String id;
private String name;
private String country;
private List<Apartment> apartments;
}
Apartment POJO is:
@Document(collectionName = "apartments")
public class Apartment {
@DocumentId
private String id;
private String name;
private Integer zip;
}
CityRepository which fetches data from cities collection
public interface CityRepository extends FirestoreReactiveRepository<City> {
}
On calling findById(nyc) returns apartments as null. I want to populate subcollection as well in city object.
Hi Dmirty,
In the given example pets are stored as part of user object(collection) but I want to store pets in a separate sub collection under users collection.
Actual ask is pets should be subcollection like below: So, it would be helpful if you can provide an example to store pets as subcollection and then how to retrieve it.