MichaelSolati / geofirestore-js

Location-based querying and filtering using Firebase Firestore.
https://geofirestore.com
MIT License
505 stars 58 forks source link

query on collectionGroup is going weird. #192

Closed kosuel closed 3 years ago

kosuel commented 4 years ago

There are collection groups called 'inventories'. When I query on collection group, geofirestore returns only one result.

Steps to Reproduce

There are two users and they have their own inventory like below.

users/kosuel/inventories/marble users/yuna/inventories/dchero

And I query with below code.

const query = geoFirestore.collectionGroup('inventories')
                    .near({ center: new admin.firestore.GeoPoint(data.latitude, data.longitude), radius: radiusInKm })

const querySnapshot = await query.get();

This returns only one result instead of two no matter how large radius I give. This code runs in firebase http trigger so I can't use onSnapshot function on query.

MichaelSolati commented 3 years ago

I'm sorry I took forever to get to this, but I think I may have possibly pinned down the issue. The error logging I got from firebase was less than ideal so I had to do some googling to find this. Anyway, from what I can best tell, this is an indexing issue.

We'll need to create a new index which you can do here:

https://console.firebase.google.com/u/0/project//firestore/indexes/single-field/manage

In the exemptions area click "Add exemption." Then fill out the two steps as you see below...

Screenshot 2020-11-30 113214

2

I found this issue helpful in resolving this issue => invertase/react-native-firebase#3737

Please let me know if this helps or works for you, if I don't hear back I'm going to close out the issue in about a week.