Nodejs Data not saving on MongoDB

Hi :wave: @Ojochogwu_Dickson,

Welcome to the MongoDB Community forums :sparkles:

I preassume that you are hitting the /register route to create a user.

The above code will return an empty response instead of the expected JSON object containing the user ID because the savedUser variable is never used in the response. Instead, the response uses the user variable, which is the new user instance that doesn’t contain the _id.

So, to resolve this error, please modify the code to:

const savedUser = await user.save();
res.send({ user: savedUser._id });

If it doesn’t work as expected, please post more details regarding the error, and the workflow you’re doing.

Regards,
Kushagra