Let's say we have an error object like this:
const error = new Error('Error');
How can I store this in mongo? Tried to store it in a field with the type Object (Even tried the type Mixed) but it just stores an empty Object.
const UserLogSchema = new Schema(
  {
    ...
    error: {
      type: Schema.Types.Mixed
    }
  },
  {
    timestamps: true
  }
);
const UserLog = mongoose.model('UserLog', UserLogSchema);
Adding the error:
const userLog = await UserLog.findOne({ _id: userLogID });
userLog.error = new Error('Error');
await userLog.save();
When we try to get the error later:
const userLog = await UserLog.findOne({ _id: userLogID });
console.log(userLog.error)
It just prints {}. But the actual error is not empty.
 
     
     
    