Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
hengkiardo opened this issue May 7, 2014 · 4 comments
Closed

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

hengkiardo opened this issue May 7, 2014 · 4 comments

Comments

@hengkiardo
Copy link

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
Copy link

dunnkers commented Jun 4, 2014

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 Automattic/mongoose#964 also describes this.

@dunnkers
Copy link

dunnkers commented Jun 4, 2014

You could do this instead:

User.findById(id).exec().then(function(user) {
    user.last_login = new Date();
    user.save();
});

@sirrodgepodge
Copy link

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

@GautamSulok
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants