问题
I have the following Firestore database. The data in this firestore was added by geofirestore module https://github.com/geofirestore/geofirestore-js#example-usage.
How can i query this firestore using geofire Queries to find where the field name="Sex"
Please search a solution for React native thanks.
enter image description here
回答1:
You'll probably want to look at the docs for future queries you may have. However for the query you want it should be fairly simple...
// Create query listener
const geoQuery = geoFirestore.query({
center: new firebase.firestore.GeoPoint(10.38, 2.41),
radius: 10.5,
query: (ref) => ref.where('d.details.name', '==', 'Sex')
});
// Then listen for results as they come in
const onKeyEnteredRegistration = geoQuery.on('key_entered', (key, document, distance) => {
console.log(key + ' entered query at ' + document.coordinates.latitude + ',' + document.coordinates.longitude + ' (' + distance + ' km from center)');
});
回答2:
Above answered query by @MichaelSolati, works on the older version of GeoFireStore (2.x.x). Here is how the same query on the version 3.x.x by Michael (taken from Github Issue).
const geocollection: GeoCollectionReference = geofirestore.collection('Users');
const geoQuery = geocollection.near({
center: new firebase.firestore.GeoPoint(50.9235691,10.7218614),
radius: 10.5
}).where('d.details.name', '==', 'Sex');
来源:https://stackoverflow.com/questions/53027146/geofirestore-where-query