Devesh Agrawal
Devesh Agrawal

Reputation: 9212

How to add new entry in firebase in webAPP

This is data structure on path https://code.firebaseio.com/products2

enter image description here

Now i want to add new entry on products/2586/Variants. Say entry is 112: true

I have written this function.

$scope.AddProductVariant2 = function(Product, Variant)  {
  //ProductService.AddProductVariant (Product, Variant);

  var key = Product.ProductID;
  var productRef = firebase.database().ref();
  var updates = {};
  var variant = {};
  variant[Variant.VariantID] = true;
  updates['products2/' + key + '/' + 'Variants'] = variant;
  /*
  firebase.database().ref('products2/' + key + '/' + 'Variants').set({
    variant
  });
 */

 return productRef.update(updates);
};

But it is erasing all old entries.

How to add new entry without touching old one here?

Upvotes: 0

Views: 447

Answers (1)

MarksCode
MarksCode

Reputation: 8604

Use .update instead of .set. Set removes all previous entries.

So do ref.update(object) where object is your javscript object you're trying to insert.

Upvotes: 1

Related Questions