javascript - How can a new data be added to firebase without the post keys? -


i use following code add new data firebase.

var postdata = {             nsn: nsn,             productname: productname,              associatedcontractnumber: associatedcontractnumber,             itemquantity: itemquantity,             viewable_by: uid,         };          inventoryid = firebase.database().ref().child('posts').push().key;          var updates = {};         updates['/businesses/' + uid + '/inventory/' + inventoryid] = postdata; 

what want create list of nsns in child "nsn" without uniquely generated post ids. attempt add nsn child nsn keeps replace old new nsn. instead of 10 different nsns got 1 recent 1 added. used code

var postnsn = {             nsn: nsn,          };        updates['/businesses/' + uid + '/national_stock_numbers/' + nsn] = postnsn; 

the above replaces existing number new 1 instead of adding new one

i tried

  var nsnref = database.ref('/businesses/' + uid + '/nsns/')   nsnref.set({             nsn: nsn,         }) 

but nothing happens. how can add new nsn child nsns without uniquely generated keys?

just use push()

say if had , nsn object

var nsn = { ... } firebase.database().ref().child('posts').push(nsn); 

doing push item end of nsn array , firebase take care creating unique key @ time of pushing.

remember firebase don't know arrays knows objects.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -