1

How I can access the whole object where phoneNo = 222 and update its lang and lat

 var db = new Firebase("myFB/names"); names { -K7VQBTELD4FQE1HL1U{ phoneNo: 111, long: 126, lat: 458 } -K7WJGBTELD4FQ1EHL1U{ phoneNo: 222, long: 547, lat: 951 } } 

1 Answer 1

4

A Firebase query requires an order by function, then you can restrict to a criteria like equalTo().

var ref = new Firebase("<my-firebase-app>/names"); var query = ref.orderyByChild('phoneNo').equalTo('222'); 

Then you can create a listener that will retrieve the value. The value will come back as an DataSnapshot, which contains the associated reference. Using that reference you can process whatever updates you need.

query.on('value', function(snap) { var obj = snap.val(); var snapRef = snap.ref(); snapRef.update({ lat: 32.332325, long: 124.2352352 }); }); 

However, you don't need to reed the object to update it. In your case, you're using a push-id as a key for /names. Perhaps an easier lookup would be the phoneNo key. Then you could do the following:

var ref = new Firebase('https://my-firebase-app/names/222'); ref.update({ lat: 32.332325, long: 124.2352352 }); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.