Reputation: 4292
It's simple. I have an object called obj
and the reference called ref
when I do:
ref.push(obj, function(err){});
or
ref.push().set(obj, function(err){});
how do I get the auto generated ID of the recently saved object?
Upvotes: 2
Views: 1588
Reputation: 598775
The push
function returns a reference to the newly created object.
var newRef = ref.push();
console.log(newRef.name());
newRef.set(obj, function(err) {});
Note that in the above snippet no data is sent to the server until the call to set
. The push()
method is pure client-side, as long as you don't pass any data into it.
https://www.firebase.com/docs/web/api/firebase/push.html
Upvotes: 3