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

245
Vistas
How to create Firestore subcollection using the new WebSDK 9?

Basically all I want to do is create a subcollection in my document, but using the webSDK 9, the tree-shakable SDK.

I've found solutions, but all of them are outdated and use the old sdk.

If this helps, I'm using NextJS and ES6.

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

0

You need to use the DocumentReference of the Firestore doc to which you want to add a subcollection, as follows:

const docRef = ....;
const docSubcollectionRef = collection(docRef, 'theSubColl');
await addDoc(docSubcollectionRef, {foo: 'bar'});

More concretely, if you have a doc in the theTempoColl collection with id doc1 (i.e. docRef = doc(db, 'theTempoColl', 'doc1')), the above code will generate a document with the following path: theTempoColl/doc1/theSubColl/{auto_generated_Id}

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can use also setDoc if you define specific document id.

import {db} from './config';
import {setDoc, doc } from '@firebase/firestore'

export default function Page(){
 const createDocWithSpecificId = async () => {
  cosnt docRef = doc(db, 'collection_name', 'specific_id');
  const createDoc = await setDoc(docRef, {foo : 'bar'});
 };
}

Thank you.

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