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

115
Vistas
Add object inside nested array in Mongoose

I am working on a web app (using Mongoose).

This is my Users JSON:

[
  {
    _id:'2819vnablj3490fa',
    name:'Bob',
    subscriptions:[
      {
        _id:'s3989408121',
        plan:'Premium',
        services:[
          {
            _id:'2237fdas2323',
            service_name:'Insurance',
          },
           {
            _id:'37280172918',
            service_name:'Consulting',
          },
            {
            _id:'27847378172',
            service_name:'Consulting',
          }
        ]
      }
    ]
  }
]

In my example I would like to:

  1. Get user with id= 2819vnablj3490fa (Bob)
  2. Get subscription with id = s3989408121
  3. Add a new service ({_id:'1920910212',service_name:'Scouting'}) to services

I tried to do the following:

var new_service = {id:'1920910212',service_name:'Scouting'}

  Label.findOneAndUpdate(
      { _id: "2819vnablj3490fa","subscriptions._id":"s3989408121"},
      { $addToSet: {services:new_service} }
    );

Actually, this is one of the many solutions that I have adopted but I still can't get out of it.

Could u help me ?

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