Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

238
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!