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