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

If createdAt or updatedAt is already present, ignore adding it #31

Open luckydev opened 9 years ago

luckydev commented 9 years ago

If a schema already has createdAt field, dont add it. Instead, add updatedAt field alone and maintain it. Vice versa for the updatedAt field.

Right now in version 0.3.0, this is the error I get when createdAt is already there and if I use mongoose-timestamp in that schema.

/Users/Anand/xyz/node_modules/mongoose-timestamp/index.js:34
      .get( function () {
       ^
TypeError: Object #<Object> has no method 'get'
    at timestampsPlugin (/Users/Anand/xyz/node_modules/mongoose-timestamp/index.js:34:8)
    at Schema.plugin (/Users/Anand/xyz/node_modules/mongoose/lib/schema.js:570:3)
    at Object.<anonymous> (/Users/Anand/xyz/models/session_token.js:12:20)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/Users/Anand/xyz/models/agent.js:17:20)