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

docs(timestamps): clarify that replaceOne() and findOneAndReplace() overwrite timestamps #14337

Merged
merged 1 commit into from Feb 7, 2024

Conversation

vkarpov15
Copy link
Collaborator

Fix #14309

Summary

Our docs could be a bit more explicit about how findOneAndReplace() and replaceOne() update timestamps. Unfortunately there's no way for Mongoose to prevent overwriting timestamps in with replaceOne() and findOneAndReplace(), so we should document this and avoid implying that Mongoose prevents updating createdAt on all query methods.

Examples

@vkarpov15 vkarpov15 added this to the 8.1.2 milestone Feb 6, 2024
Comment on lines +71 to +72
console.log(doc.createdAt); // 2022-02-26T17:08:14.008Z
console.log(doc.updatedAt); // 2022-02-26T17:08:14.008Z
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe instead of logging times do a == to show that they equal? or is it possible the times may be slightly off?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think console.log() is better because 1) easier to copy/paste and see the output, 2) doesn't rely on loose equality - doc.updatedAt is a date instance, so == is fine but === is not

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes i meant === (triple), forgot js particularity for a moment

@hasezoey hasezoey added the docs This issue is due to a mistake or omission in the mongoosejs.com documentation label Feb 7, 2024
@vkarpov15 vkarpov15 merged commit 2c34102 into master Feb 7, 2024
2 checks passed
@vkarpov15 vkarpov15 deleted the vkarpov15/gh-14309 branch February 7, 2024 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs This issue is due to a mistake or omission in the mongoosejs.com documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

When using replaceOne, the createdAt timestamp is being updated like the updatedAt
2 participants