I achieved this effect by setting _createdOn to pre-save the schema (only on the first save):
schema.pre('save', function(next) { if (!this._createdOn) { this._createdOn = new Date(); } next(); });
... and the prohibition of changes from another place:
userSchema.pre('validate', function(next) { if (self.isModified('_createdOn')) { self.invalidate('_createdOn'); } });
eagor source share