I have the following structure of my database:
Inside the Location collection there is a document and in it there is Lat, Lon coordinates:
My final goal is to get all of the Lat, Lon coordinates of all users however im already stuck on how to get to Location collection if I dont know the document name where it is?
Is there some query that I can do to move straight inside to something like WhereEqualTo("Lat")
?
To begin I tried the following:
db.collection("Users").get()
.addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
List<String> listID = new ArrayList<>();
for (QueryDocumentSnapshot doc : task.getResult()) {
listID.add( doc.getId() );
}
However it returns me null list.
Thank you
You need to use a Collection Group Query , as follows:
db.collectionGroup("Location").get()
.addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
@Override
public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
// ...
}
});
This runs a query across all collections names Location
in your database.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.