geofirestore-js: ERROR: Array is not a function (evaluating 'e.docChanges()')

screenshot_2018-08-07-13-07-15

Here is my code:

 const db = firebase.firestore();
    const userCollection = db.collection('interviews');
    const geoobj = new GeoFirestore(userCollection)
    let query  = geoobj.query({
      center: coordinates,
      radius: 100,
    //  query: (ref) => ref.where('d.count', '==', 1)


    });
    query.on("ready", () => this.setState({ loading: false }));
    query.on("key_entered", (key, coords, distance) => {
      console.log("asdada",key);
    });

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 15 (2 by maintainers)

Most upvoted comments

HI @joscmw95 thanks for the input i will try and share the results.

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.

@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.

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 ! 😃

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)

Probably the same reason as in #19, try to update firebase.