Node.js / Mongoose save systemNotification when user registers

75 views Asked by At

i´d like to do save a Notification, when creating a new user. Within the save-Method of the user, I tried this:

var notification = new Notification({
                'displayName': 'Signup-Error',
                'type': 'error',
                'category': 'user',
                'text': info.message
            });
            notification.save();

But I´m getting the following error:

Redefinition of 'Notification'

what am I doing wrong?

my Model:

var notificationSchema = new Schema({
displayName: {
    type: String,
    trim: true,
    required: 'displayName is required'
},
type: {
    type: String,
    trim: true
},
category: {
    type: String,
    trim: true
},
text: {
    type: String,
    trim: true,
    required: 'Text is required'
},
isRead: {
    type: Boolean,
    default: false
},
date: {type: Date, default: Date.now}
 });
  mongoose.model('Notification', notificationSchema);

I think it´s because I require() the Model two times - in the user-controller and in the notification-controller.

0

There are 0 answers