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

256
Vistas
Insert a index into a existing mongoose document if it not exists

I want to create a function that creates the "user" document on mongoose. But in future updates of my app, I will need to append more indexes inside the document. So, I'm making a function to create the user if it not exists, and add index by index if it not exists.

In fact, I don't know what's the correct function to put right here (-> "add"). Can you, dear reader, show me the light?

let player = await User.findOne({ _id: id })
    if (!player) {

        User.create({ _id: id })
        
        player = await User.findOne({ _id: id })
    }

    if (!player.name) player."add"({ name: username })
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