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

updatedAt not updated when i do some updated to document #13

Closed hengkiardo closed 10 years ago

hengkiardo commented 10 years ago

when i do update to docement, field updatedAt not updated with current Date time. example my query

User.findByIdAndUpdate(id, { last_login: new Date() }).exec()
dunnkers commented 10 years ago

It's actually impossible to hook middleware onto update, findByIdAndUpdate, findOneAndUpdate, findOneAndRemove and findByIdAndRemove in Mongoose at the moment.

This means that no plugin is actually run when using any of these functions.

Check out the notes section in the Mongoose documentation for middleware. Issue LearnBoost/mongoose#964 also describes this.

dunnkers commented 10 years ago

You could do this instead:

User.findById(id).exec().then(function(user) {
    user.last_login = new Date();
    user.save();
});
sirrodgepodge commented 8 years ago

any idea what was causing this (dates not updating on "update" command)? I'm getting this too...

GautamSulok commented 6 months ago

Why this is closed? It is actually a huge issue developers facing right now