ksmithut/mongoose-created-at

View on GitHub
index.js

Summary

Maintainability
A
0 mins
Test Coverage
'use strict';

module.exports = function createdAt(schema, options) {
  // Set the default options
  options = options || {};
  var createdAtPath = options.createdAtPath || 'createdAt';
  var index        = options.index || false;

  // Set the new path
  schema
    .path(createdAtPath, Date)
    .path(createdAtPath).default(Date.now);

  // If the index option was set, set the index
  if (index) {
    schema.path(createdAtPath).index(index);
  }

};