Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

390
Vistas
Firebase 9 - how to chain 'addDoc' or similar to a 'collection'?

Previously in Firebase you could add a document like this:

const myNewDoc = await db.collection('some-collection-name').add({ //Document details here... });

With the introduction of Firebase 9 this no longer works.

Instead of .add I think I am supposed to use an imported .addDoc method.

But it seems I cannot chain .addDoc onto .collection.

If I try to do something like this:

const myNewDoc = await db.collection('some-collection-name').addDoc({ //Document details here... });

TypeScript throws this error:

Property 'addDoc' does not exist on type 'CollectionReference<DocumentData>'.ts(2339)

I could create something more verbose like this:

const someCol = collection(db, "some-collection-name");
const newDoc = await addDoc(someCol, {
    //Document details here...
});

But I would rather "chain" it like before.

Is that possible? How would it be done?

And should I even be using .addDoc? Or something else?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The addDoc() is a top level function in Modular SDK. Try refactoring your code like this:

import { collection, addDoc } from "firebase/firestore"; 

const newDoc = await addDoc(collection(db, "some-collection-name"), {
  // Document Data
});
console.log("Document written with ID: ", newDoc.id);

The documentation has examples of both name-spaced and the new syntax.


If you are using compat version to use older syntax then you would have to use add() itself.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda