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

244
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 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