firebase / geofire-js

GeoFire for JavaScript - Realtime location queries with Firebase
MIT License
1.44k stars 345 forks source link

child_added in firebase not working with geofire reference in Real time database #176

Closed jackphuongvu closed 3 years ago

jackphuongvu commented 5 years ago

Version info

I think there is a problem with index rule of Firebase ref because it worked well with other reference however it just didn't work with this ref from geoFirejs

Firebase: 3.6.9 GeoFire: 4.1.2 Other (e.g. Node, browser, operating system) (if applicable):

Test case

Steps to reproduce

const onChildChange = (data) => {
      const position = data.val();
      console.log('geofire with Firebase');
    }

firebase.database().ref('geofire').limitToLast(1).on('child_added', onChildChange);

This is my code inside componentDidMount from my React Native project

Expected behavior

Actual behavior

puf commented 3 years ago

My first guess is that the node you add is not added to the end of the list, so it doesn't match the .limitToLast(1) condition in your query. GeoFire sets a .priority value on each node, which affects how nodes are ordered. I'd highly recommend only accessing the geofire node though the geofire-js API.

Given how long this issue has been open, I'm going to close it. If the problem is still relevant to you, please post a full MCVE with which we can reproduce the problem.