Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

155
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda