Skip to content

Handle timestamps on arbitrarily deep subdocs #8809

Open

Description

@vkarpov15

Re: #8799

Activity

  1. added
    enhancementThis issue is a user-facing general improvement that doesn't fix a bug or add a new feature
    on Apr 17, 2020
  2. added this to the 5.x Unprioritized milestone on Apr 17, 2020
  3. Hackerbee commented on Jun 1, 2024

    @Hackerbee

    just reporting an observation here. I have read the conversation at #8799 and thought to just report this at the moment and see if I can fix this later.

    Here's the query I'm running.

    await Courses.findByIdAndUpdate(
        courseId,
        { $push: { "modules.$[].lessons.$[].points.$[point].scenes": { $each: scenes } } },
        { runValidators: true, timestamps: true, arrayFilters: [{ "point._id": pointId }] },
      );

    debug output:

    Mongoose: courses.findOneAndUpdate(
      { _id: ObjectId("6656a85459ca496d399a2729") },
      {
        $setOnInsert: { created_at: new Date("Sat, 01 Jun 2024 05:25:23 GMT") },
        $set: { updated_at: new Date("Sat, 01 Jun 2024 05:25:23 GMT") },
        $push: {
          "modules.$[].lessons.$[].points.$[point].scenes": {
            $each: [
              {
                position: 1,
                narration:
                  "Welcome to the module on Basics of Options Trading. In this lesson, we will explore the key differences between options and stocks.",
                _id: ObjectId("665ab0c323c811da3abe8c61"),
              },
              {
                position: 2,
                narration: "Let's start by understanding the fundamental distinction between options and stocks.",
                _id: ObjectId("665ab0c323c811da3abe8c62"),
              },
            ],
          },
        },
      },
      { arrayFilters: [{ "point._id": ObjectId("6656a85459ca496d399a272d") }], runValidators: true }
    );

    currently it is only updating at the root level (as shown in the debug output).

    Let me know if I am right in considering the core problem that has to be determined/solved.

    • how to determine the level at which we have to put the timestamps from the query?
    • and then where to update the timestamps
      • at the nearest ancestor schema with timestamps enabled and stop.
      • at all the ancestor schemas with timestamps enabled while bubbling up till root.

    I have not read the code and it will really take a lot of time to find any edge cases. While I do that, let me know your opinions/suggestions.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementThis issue is a user-facing general improvement that doesn't fix a bug or add a new feature

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions