Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Push multiple objects at once

How can I do multiple object pushes at once with angularfire2?

Just pushing an array of objects doesn't set keys for each object.

this.af.database.list('/symbols/').push({
  typ: "symbol1",
  // ....
});
this.af.database.list('/symbols/').push({
  typ: "symbol2",
  // ....
});
like image 273
daniel Avatar asked Mar 30 '17 13:03

daniel


1 Answers

With the regular Firebase JavaScript SDK, you can accomplish this with:

var updates = {};
updates['/symbols/'+ref.push().key] = {
  typ :"symbol1", ....
};
updates['/symbols/'+ref.push().key] = {
  typ :"symbol2", ....
};
ref.update(updates);

Since AngularFire2 is built on top of the normal Firebase JavaScript SDK, they interop perfectly. So you can just use the Firebase JavaScript SDK for this operation.

like image 140
Frank van Puffelen Avatar answered Oct 16 '22 18:10

Frank van Puffelen