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

156
Vistas
spread operator on moongose object is not working

I am saving document to mongodb like this

async addUser(user: User): Promise<User> {
    const newUser = new this.userModel(user);
    return newUser.save();
}

now if i use this function

const newUser = await this.userService.addUser(user);

and print newUser it prints the values of valid object like name,email

now if i try

const clientInfo = { ...newUser, ...newClient.clientInfo };

it empty my clientInfo object

and if i try

const clientInfo = { ...newClient.clientInfo ,...newUser};

then this just shows the clientInfo properties.

I tried

async addUser(user: User): Promise<User> {
    const newUser = new this.userModel(user);
    return newUser.save().then((response) => response.toObject());
}

but toObject is not helping.

I just want to merge newUser object with someother object.

const clientInfo = { ...newClient.clientInfo ,...newUser};

What can be the issue?

Update1

Tried this that says using toObject() can help. But this did not work.

When i tried

newUser.save().lean()

but this shows

Property `lean` does not exist on type Promise<Document<any, any, User
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