Open marvinsxtr opened 5 years ago
+1 same issue
Any news on this issue?
same here
I tried both Firestore.instance.collectionGroup('collectionName')
and Firestore.instance.collectionGroup('collectionName').reference()
but neither of them worked
Well I found this article written by Tod. It's like the prerequisites when you want to do the collection group query. This might be the reason why Firestore does not fetch you any results back while the GeoFlutterFire package did not show the error either.
https://firebase.googleblog.com/2019/06/understanding-collection-group-queries.html
I have not tried this solution because after reading the article, I decided to go with another top-level collection for my data =)
For me this is working perfectly fine. If you have questions you can contact me :)
EDIT: I can give some general advise here:
@webertim Could you please post example how your collectionGroup query looks using GeoFlutterFire?
@ramunasjurgilas Because this is a private project, I changed some of the variable names. Still should be fine for you to check out the logic behind it.
class FirestoreManager {
Firestore _firestore = Firestore.instance;
Geoflutterfire geoflutterfire = Geoflutterfire();
Stream<List<DocumentSnapshot>> getPositionsInRange(double latitude, double longitude) {
GeoFirePoint centerGeoPoint = geoflutterfire.point(latitude: latitude, longitude: longitude);
Query collectionRef = _firestore.collectionGroup("places");
double radius = 10;
String field = "geoInfo";
return geoflutterfire.collection(collectionRef: collectionRef).within(center: centerGeoPoint, radius: radius, field: field);
}
}
There is no real magic going on here. I am still thinking there are problems with your Firestore configuration.
@webertim Thanks for the snippet. For me it is still not working. I have intention, that something is wrong with my structure and field I am passing. For me geo info located in: address.g
@ramunasjurgilas Ok so I guess you are trying a collectionGroup-Query on playrooms right?
The first thing I notice is your structure. I am not 100% sure but I think your playground documents need a seperate field for the geo information. So i recommend not to put the 'g' field inside the 'address' map.
Another thing I see is, that your 'field' looks kind of wrong. Again I am not sure, but I think the 'g' field should be a map with a field 'geohash' (type String) and a field 'geopoint' (type Geopoint).
Same problem again... This is a private project so I cannot share a screenshot of the whole document/collection. But still here is a screenshot of the geoInfo map (in your case this would be the 'g' field), which is a top-level field.
If you change your Firestore stuff your code should look like this:
class FirestoreManager {
Firestore _firestore = Firestore.instance;
Geoflutterfire geoflutterfire = Geoflutterfire();
Stream<List<DocumentSnapshot>> getPositionsInRange(double latitude, double longitude) {
GeoFirePoint centerGeoPoint = geoflutterfire.point(latitude: latitude, longitude: longitude);
Query collectionRef = _firestore.collectionGroup("playrooms");
double radius = 10;
String field = "g";
return geoflutterfire.collection(collectionRef: collectionRef).within(center: centerGeoPoint, radius: radius, field: field);
}
}
@webertim Thanks for your help. You was right I needed to set these, geohas and geopoint. But I did it inside address structure.
@ramunasjurgilas Happy to hear that :)
But I did it inside address structure. Interesting, I was not sure about that. But thanks for the information!
@webertim thank you for your feedback... Just to add after struggling a couple of hours, that you need to build an index for your subcollection : there will be no error message with index automatic generation link. This need to be manually generated in Firestore console...
@webertimgracias por sus comentarios... Solo para agregar después de luchar un par de horas, que necesita crear un índice para su subcolección: no habrá ningún mensaje de error con el enlace de generación automática de índice. Esto debe generarse manualmente en la consola de Firestore...
how to add the index
Hey @DarshanGowda0, I really appreciate the simplicity of your plugin.
When i tried to use a StreamBuilder with it like described in this issue, it works perfectly fine.
But when i changed the collectionReference to a collection group, there are no results. Can you confirm that collection group queries are unsupported?