Grab the id when you get the data
For Firebase, at least when you retrieve the entries, you also get the id. Therefore, a simple solution is to save the identifier. If you donβt have a convenient place for this, you can simply insert it into the data:
firebaseRef.on('child_added', function(snapshot) { var data = snapshot.val(); data.id = snapshot.name();
Of course, if you do this, you must remember that you need to return it before sending the data back to the server.
Use snapshot
Firebase-specific again, you can save the link to the snapshot and pass this in place of the data. I do not really like this approach personally, but I could not cover up what neat internal principle it violates.
In some cases, this is very convenient, since at any time you will have a link to the data, id and the Firebase object; quite comfortable.
Put the identifier in the data
A common practice in NoSQL is simply to insert identifiers into the data - there is nothing wrong with that, except for a small additional storage space - in most cases the use is negligible. Then, when you retrieve the records, the identifier is already in the data, and everything is in order.
For Firebase, you can generate an identifier and put it in the data at creation time. The following trick came from one of their open sources:
var data = {...}; var id = firebaseRef.push().name();