Simple mongoose plugin to add a created_at property to your schema, set on object save at the first time.
npm install --save mongoose-plugin-createdat
const Schema = require('mongoose').Schema;
const mongoosePluginCreatedAt = require('mongoose-plugin-createat');
let MySchema = new Schema({ ... });
MySchema.plugin(mongoosePluginCreatedAt);
Available options:
index
: if you want to index the propertyname
: the name of the field - default is created_at
const Schema = require('mongoose').Schema;
const mongoosePluginCreatedAt = require('mongoose-plugin-createat');
let MySchema = new Schema({ ... });
MySchema.plugin(mongoosePluginCreatedAt, {
index: true,
name: 'created_at_custome_name',
});
MIT