Below is an object literal I am trying to save to MongoDB. It is defined within the app.js file which is an Express server. As the object is hardcoded within the server, my
I found a few problems when trying to reproduce this locally.
You're not calling next() in newsSchema.pre('save')
Should be
newsSchema.pre('save', function(next){
if( !this.addedOn ) this.addedOn = new Date();
if( !this.addedBy ) this.addedBy = adminUser;
next();
});
You also need to make sure that you are connected to the db before doing any of this stuff, not sure if you are or not since i didn't see that part of the code.