I'm a totally new Firebase user, trying to build a simple application -- and I'm running into an odd issue that I haven't been able to find a solution to.
Here's what I'm doing.
I've got a simple Firebase database of users, that looks something like this:
{
"users": {
"randomlyAssignedId": {
"phoneNumber": "+18882223333"
}
}
}
The idea is that I'll have one user object (and each user object only contains a phoneNumber
field) for each user using my service.
I've got this stored in Firebase and working already.
Now, here's where things are getting tricky. I want to write a query which returns a user by their phoneNumber
. So, after reading the Firebase docs, here's what I came up with:
var Firebase = require('firebase');
var users = new Firebase('https://demo.firebaseio.com/users');
users.orderByChild('phoneNumber').equalTo('+18882223333').limitToFirst(1).once('value', function(snapshot) {
console.log('API call succeeded:', snapshot.val());
}, function(err) {
console.log('Firebase returned an error:' err);
});
When I run this code sample, the user object is logged to the console successfully (it found the match, yey!), however -- the callback never finishes.
According to the Firebase docs for .once()
: https://www.firebase.com/docs/web/api/query/once.html the success (or error callback) should fire exactly ONE time.
This doesn't appear to be happening :(
Could anyone tell me if this is the desired behavior, or if I'm doing something wrong?
Thanks! <3