I want to save user as object in rating object, but when I am going to add it its userId adding instead of whole user object ?
const reviewSchema = new mongoose.Schema(
{
name: {
type: String,
required: [true, "name is require"],
},
rating: {
type: Number,
default: 0,
},
comment: {
type: String,
},
user: {
type: mongoose.Schema.Types.ObjectId,
ref: "Users",
required: [true, "user require"],
},
},
{ timestamps: true }
);
This is the model of rating in which user object added.
const user = await userModel.findById({ _id: req.user._id });
console.log(user);
// review object
const review = {
name: user.name,
rating: Number(rating),
comment,
user,
};
This is the controller function in which user has gotted from request.params._id, but when I am going to save user object only its ID is being saving in database.