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

264
Vistas
How to create a collection in FireBase using React

The problem is pretty simple. I want to create a document that has a collection in it. An alternative way of wording it would be I need to make a collection in a document.

I need to be able to do this in React.

Visual: collection -> document -> collection

Here is where I need to add the code:

const addUser = async () => {
    await addDoc(usersCollectionRef, {
      name: newName,
      grade: Number(newGrade),
      role: newRole,
      hours: Number(newHours),

      //Collection Creation should go here as this is where I am making the new document.

    })
  }

Note: This is react and not react native

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

0

If I understood you correctly, you want to make a new collection inside the doc you just created in your code above. A collection cannot be empty, therefore you have to put some data inside a document in your collection. One way this can be done is like this:

const usersCollectionRef = colleciton(db, 'users')

const addUser = async () => {
    const document = await addDoc(usersCollectionRef, {
      name: newName,
      grade: Number(newGrade),
      role: newRole,
      hours: Number(newHours),
    })

    const newCollectionRef = collection(db, 'users', document.id, 'name of new subcollection')

    await addDoc(newCollectionRef, {
        data: 'Hello World!',
    })
  }
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