BeingSuman BeingSuman - 1 year ago 106
Javascript Question

Can i control the unique key/ID that gets generated when i push an object to Firebase Array?

Am using AngularFire

method, which under the hood calls
, to add an child object to a parent.

Firebase documentation says that
method :

Generates a new child location using a unique key and returns a Firebase reference to it.

I wanted to have control over the Unique Key or ID that gets generated for the object i push. Like i wanted to prefix a constant to the random ID and then save it. Is it possible ??

Answer Source

Calling push() is a pure client-side operation. So you can:

var newRef = ref.push();
var newKey = newRef.key();
var realRef = ref.child("myPrefix_"+newKey);
realRef.set({ title: 'tadaaa', body: 'New child with a push ID and a custom prefix' });
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download