I have a database stored on Firestore with the following structure:
-Collection
----Document
-------Subcollection
----------Documents with Data
----Document
-------Subcollection
----------Documents with Data
----Document
-------Subcollection
----------Documents with Data
I want to retrieve the documents located in the subcollection but I can't seem to be able to with the following code:
@Data
@AllArgsConstructor
@NoArgsConstructor
@Document(collectionName = "states")
public class State {
@DocumentId
String name;
int num_of_listings;
Flux<Listing> listings;
}
The code for Listing is:
@Data
@AllArgsConstructor
@NoArgsConstructor
@Document(collectionName = "listings")
public class Listing {
@DocumentId
String id;
String description;
}
Imagine each "State" contains some "Listing"s. Each POJO is accompanied by a controller with a repository injection of type FirestoreReactiveRepository like the following:
@Repository
public interface StateRepository extends FirestoreReactiveRepository<State> {
}
@RestController
@RequestMapping("/states")
@Slf4j
@RequiredArgsConstructor
public class StateController {
private final StateRepository stateRepository;
@GetMapping
private Flux<State> getAllStates() {
return stateRepository.findAll();
}
}
When I'm requesting all the states with getAllStates() I get a null listings field while all other fields are initialized, as expected. How can I possibly achieve the desired functionality?
@Edit: If there is a way to access the subcollection directly, it is also welcome!