Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

235
Visualizações
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",
  // ....
});
over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

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.

over 4 years ago · Santiago Trujillo Relatório

0

Based on @Frank's answer, improvised it to have a reducer and a promise resolver> Here is the final version:

const admin = require('firebase-admin');
const types = [
  {
    type: "symbol1"
  },
  {
    type: "symbol2"
  }
];
const rootRef = admin.database().ref();
const ref = rootRef.child(`/symbols`);

// prepare updates object based on types array.
let updates = types.reduce((update, type) => {
  let id = ref.push().key;
  update[`/symbols/${id}`] = type;
  return update;
}, {});

await rootRef.update(updates)
.then((response) => {
  return res.status(201).json({message: "Records added successfully"});
})
.catch((error)=>{
  res.sendStatus(500);
})
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda