Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

163
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!