Skip to content

Conversation

baruchiro
Copy link

Description

Added a new WithTimestamp type that adds createdAt and updatedAt fields
of type Date to any object shaped type. This follows the same pattern as
the existing WithId type and allows for easy addition of timestamp fields
to MongoDB document types.

Is there new documentation needed for these changes?

What is the motivation for this change?

https://jira.mongodb.org/browse/NODE-6855

Release Highlight

Fill in title or leave empty for no highlight

Double check the following

  • Ran npm run check:lint script
  • Self-review completed using the steps outlined here
  • PR title follows the correct format: type(NODE-xxxx)[!]: description
    • Example: feat(NODE-1234)!: rewriting everything in coffeescript
  • Changes are covered by tests
  • New TODOs have a related JIRA ticket

Added a new WithTimestamp type that adds createdAt and updatedAt fields
of type Date to any object shaped type. This follows the same pattern as
the existing WithId type and allows for easy addition of timestamp fields
to MongoDB document types.
@baruchiro baruchiro requested a review from a team as a code owner March 13, 2025 08:13
@dariakp dariakp added tracked-in-jira Ticket filed in MongoDB's Jira system External Submission PR submitted from outside the team labels Mar 13, 2025
@nbbeeken
Copy link
Contributor

Hey @baruchiro, thanks (again!) for reaching out. We are not sure if the driver is the best place for such a type as the driver is not responsible for adding these fields, users can use a multitude of types for their createdAt/updatedAt fields if they even have them, since they need to have the logic to attach them.

Given the breadth of possibilities we are not confident these would lend much value to anyone who isn't using this exact pattern, can you elaborate on where these fields come from for your use case and why having them in the driver is beneficial?

For additional context, our similarly named WithId<> type is used by the driver when it is responsible for adding the _id field to documents that don't have it, so we need a type to represent that change to a given input.

@baruchiro
Copy link
Author

@nbbeeken Now you're saying that, I see I was wrong.
Yes, I used the WithId type as a reference, and this confused me to contribute it into the driver.

The' mongoose' system adds the "timestamp" fields if you set timestamp: true to the schema. So it must be implemented there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

External Submission PR submitted from outside the team tracked-in-jira Ticket filed in MongoDB's Jira system

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants