drudge / mongoose-timestamp

Adds createdAt and updatedAt date attributes that get auto-assigned to the most recent create/update timestamp
Other
308 stars 64 forks source link

Indices for createdAt and updatedAt attributes #36

Closed pbespechnyi closed 8 years ago

pbespechnyi commented 8 years ago

Is there any way of defining indices for createdAt and updatedAt attributes?

drudge commented 8 years ago

I've added the ability to pass extra options (like index) when defining the fields. This is available in version 0.6.0 on npm.

Example:

var opts = {
    createdAt: {
        name: 'customNameCreatedAt',
        type: Date,
        index: true
    },
    updatedAt: {
        name: 'customNameUpdatedAt',
        type: Date,
        indexed: true
    }
};

var CustomizedTypeOptionsTimeCopSchema = new Schema({
    email: String
});

CustomizedTypeOptionsTimeCopSchema.plugin(timestamps, opts);
pbespechnyi commented 8 years ago

Thanks!