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

199
Views
MongoDB - how to add subcollection?

When i was working with firebase, adding new subcollection to existing collection was preety easy:

db.collection('SOME_COLLECTION').doc('someId').collection('SOME_COLLECTION_2').add({ some: object })

with this one line i've create many of the subcollections. But how to do this with simple mongodb and nodejs/typescript?

I try in this way:

const result = await db.collection(COLLECTIONS.USERS).findOne({ _id: new ObjectId(id)}).//error

but i can't call another collection function to create him.

So I need a help, can someone tell me how to create subcollection in mongodb?

Thanks for any help!

PS. or is maybe a better approach with using subcollection in mongodb?

about 4 years ago · Juan Pablo Isaza
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!