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

wish: allow customizing the name of the columns #12

Closed markstos closed 10 years ago

markstos commented 10 years ago

Thanks for this plugin.

It would be nice if the column names 'updatedAt' and 'createdAt' could be customized.

In our case, we are considering adding it to an existing system where we already have a different naming convention established.

drudge commented 10 years ago

You can specify custom property names by passing them in as options like this:

mongoose.plugin(timestamps,  {
  createdAt: 'created_at', 
  updatedAt: 'updated_at'
});
markstos commented 10 years ago

Thanks for the response.

I'm re-opening this issue because the functionality remains undocumented in the Readme.

drudge commented 10 years ago

Documented.

penmets commented 8 years ago

Custom property names are not working. It is taking default names only. I am giving like this.

var timestamps = require ("mongoose-times");
 mongoose.plugin(timestamps,  {
  createdAt: 'createdDTS', 
  updatedAt: 'lastModifiedDTS'
});

My response:

"createdAt" : ISODate("2016-05-16T10:02:48.189+0000"), 
 "updatedAt" : ISODate("2016-05-16T10:02:48.189+0000"), 
markstos commented 8 years ago

@penmets Are you using the latest version of the plugin, 0.5.0? When you run "npm test" in the distribution, does it pass? The test suite contains test coverage for custom column names.

If some test coverage seems to be lacking for a case that still fails, please contribute a pull request that adds a new failing test case.

penmets commented 8 years ago

now i insatlled mongoose-timestamp 0.5.0 version. this is my code

var mongoose = require('mongoose'),
    Schema = mongoose.Schema,
    timestamps = require('mongoose-timestamp');

var MySchema = new mongoose.Schema({
    title : String,
    media : [{
           mediaUrl : String
    }]
});
MySchema.plugin(timestamps,{ createdAt: 'createdby',
 updatedAt: 'updatedby'});

module.exports = mongoose.model('my', MySchema);

I am gettiong this error , when i am calling create function TypeError: Cannot read property 'numAsyncPres' of undefined

markstos commented 8 years ago

The string "numAsyncPres" does not appear in this code base. If you think there's a problem with this plugin, add a test case to the test suite to confirm your suspicion.