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

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