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

insertMany does not take nested/subdocument schema into account for timestamps #12060

Closed
2 tasks done
eliw00d opened this issue Jul 6, 2022 · 0 comments
Closed
2 tasks done
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Milestone

Comments

@eliw00d
Copy link

eliw00d commented Jul 6, 2022

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Mongoose version

6.1.5

Node.js version

16.13.0

MongoDB server version

4.4.12

Description

insertMany adds createdAt and updatedAt if timestamps: true for parent document but not for child document with the same settings.

It honors _id: false for both parent and child documents, so I would expect this is just a bug.

I did a search for existing issues and came across one but it seems no follow-up issue was ever created: #4155 (comment)

Steps to Reproduce

const mongoose = require('mongoose')
const { Schema } = mongoose

const childSchema = new Schema(
  {
    name: { type: String },
  },
  {
    _id: false, // honored
    timestamps: true, // not honored
  }
)

const parentSchema = new Schema(
  {
    child: {
      type: childSchema,
    },
  },
  {
    timestamps: true,
  }
)

const Test = mongoose.model('Test', parentSchema)

async function run() {
  await mongoose.connect('mongodb://localhost:27017')
  await mongoose.connection.dropDatabase();

  await Test.insertMany([{ child: { name: 'child' } }])

  console.log(await Test.find())
}

run()

Expected Behavior

I would have expected the nested/subdocument to also have its schema options of timestamps: true honored when inserting.

@vkarpov15 vkarpov15 added this to the 6.4.5 milestone Jul 11, 2022
@vkarpov15 vkarpov15 added the has repro script There is a repro script, the Mongoose devs need to confirm that it reproduces the issue label Jul 11, 2022
@IslandRhythms IslandRhythms added confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. and removed has repro script There is a repro script, the Mongoose devs need to confirm that it reproduces the issue labels Jul 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Projects
None yet
Development

No branches or pull requests

3 participants