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

mongoose-timestamp adds 4 properties to collection when I customize the names #19

Closed IderAghbal closed 10 years ago

IderAghbal commented 10 years ago

Hello,
I have the following in my code:

var mongoose = require('mongoose'),
      Schema = mongoose.Schema,
      timestamps = require('mongoose-timestamp');
var ItemSchema = new Schema({
      name: String
});
mongoose.plugin(timestamps,  {
    createdAt: 'added_at',
    updatedAt: 'last_updated'
});
ItemSchema.plugin(timestamps);

however when I look at my item collection using mongo command line I see that there is 4 properties (added_at, last_updated, createdAt and updatedAt)
what have I done wrong? ( @drudge ? )

jspavlick commented 10 years ago

This is happening to me, too.

drudge commented 10 years ago

Aren't you adding the plugin twice if you use mongoose.plugin() and ItemSchema.plugin(). Once with the custom field names, once without.

jspavlick commented 10 years ago

Ah. Works now. Thanks! I'd suggest an update to the documentation. My error was not immediately clear to me.