Closed ektasahu027 closed 6 years ago
Probably the same reason as in #19, try to update firebase.
@MvRemmerden i am using react-native-firebase package so i have to update it...
This package isn't designed for react-native-firebase
, it's designed for the pure JavaScript firebase
library. Unfortunately it will not work. (I am open to PRs for support though)
@MichaelSolati thanks when i use firebase its work.
@MichaelSolati Will the package work for firebase-admin sdk???
@kenzdozz it should with versions 5.x.x
.
Hi, @MichaelSolati Just to let you know if you don't already. I am using react-native-firebase and geofirestore(2.2.1) seems to be working fine with it, I can read and write. Thank you very much for this library it's very helpful and easy to use! keep it up, please ! :)
Hi Michael,
Great job on the library. I am using firestore "firebase": "^4.13.1" along with geofirestore "^2.2.2". I am trying to accomplish the following query using array-contains. I have the following array example below.
array=['cat','dog'];
now i want to loop via firestore and do something like a .where('d.name','array-contains',array). See my query below for reference.
const collectionRef = firebase.firestore().collection('Consents') const geoFirestore = new GeoFirestore(collectionRef);
var arr =['cat','dog']
const geoQuery = geoFirestore.query({
center: new firebase.firestore.GeoPoint(lat, long),
radius: val,
query: (ref) => ref.where('d.name', 'array-contains',arr)
});
how can i achieve this using geofirestore, firebase and firestore.
should i update my firebase to react native firebase to be able to use the array contains method along with geofirestore?
@graig12 In Firebase docs, they usually do array-contains using a string
parameter. Your code is using an array, I'm not sure if that's the problem.
Try:
query: (ref) => ref.where('d.name', 'array-contains',arr.join(' '))
edit: However, this checks that the array at d.name
contains an element with 'cat dog'
What you seem to want to achieve is to do a 'OR' operator on the array of names against the DB, which is unfortunately not achievable with a single query in Firebase.
that is correct @joscmw95 i want to achieve an OR. Since this is not possible can how would u suggest i accomplish this ?
As written at the bottom of the docs:
Logical OR queries. In this case, you should create a separate query for each OR condition and merge the query results in your app.
You'll have to query for every element in the array and merge the results:
var arr =['cat','dog']
var results = []
arr.forEach(el => {
const geoQuery = geoFirestore.query({
center: new firebase.firestore.GeoPoint(lat, long),
radius: val,
query: (ref) => ref.where('d.name', '==', el)
})
geoQuery.on('key_entered', function(key, document, distance) {
results.append(document)
});
})
This is assuming that you want the results in random order and it is probably not performant because geo query will need to run n times. I would suggest you to just get data from a single geo query and filter the data client side.
HI @joscmw95 thanks for the input i will try and share the results.
Hi @joscmw95 are you able to share any insight here on this post of stack over flow."https://stackoverflow.com/questions/53094022/firestore-multiple-where-query?noredirect=1#comment93100280_53094022" I am attempting to do a filter on a geofirestore/firestore database that conatians a collection of books. I am trying to filter on booktype and book age however i am getting the error "uncaught error in onsnapshot firebaseError: cursor position is outside the range of the original query " the code that i am using is below.
const collectionRef = firebase.firestore().collection('Books')
collectionRef.where('d.details.BookType',"==",BookType)
collectionRef = collectionRef.where('d.details.bookage',"<=",age)
collectionRef = collectionRef.orderBy('d.details.bookage')
const geoFirestore = new GeoFirestore(collectionRef)
const geoQuery = geoFirestore.query({
center: new firebase.firestore.GeoPoint(lat, long),
radius: val,
});
geoQuery.on("key_entered",function(key, coords, distance) {
storeCoordinate(key,coords.coordinates._lat,coords.coordinates._long,newdata) });
Internally geoFirestore gets its results by using startAt
and endAt
. The way you declare your collectionRef clashes with how it works hence the cursor error.
Detailed explanation in stackoverflow
Here is my code: