Skip to content Skip to sidebar Skip to footer

Auto Increment Data On Firebase

I am currently trying to create something like this on Firebase: 'Assets': { 'asset001' : { 'name': 'DESK001', 'owner: 'owner's name', 'brand: 'HP',

Solution 1:

You seem to be going through a lot of trouble trying to make names for your assets. The way you are creating your keys you will run into trouble once you reach Asset999.

The best way to ensure that you do not have to bother with creating a unique key is letting firebase do it for you. Then upload all the info in one go.

var newKey = rootRef.push().key;

var objectToUpload = {
"owner": owner,
"brand": brand,
"name": name
};

rootRef.child(newKey).set(objectToUpload);

Post a Comment for "Auto Increment Data On Firebase"