Prerequisites
Mongoose version
7.x.x, 8.x.x
Node.js version
20.x
MongoDB server version
8.x
Typescript version (if applicable)
No response
Description
I'm trying to update the createdAt field of some documents using bulkWrite and it's not possible. It works if I use updateOne directly as a function but if I do it through a bulkWrite it doesn't work.
This only affects createdAt, updatedAt can be updated.
So far I have tested it using Mongoose v7 and v8 and both have the same issue, I would appreciate it if this could be fixed in both versions 🙇🏽♂️.
Steps to Reproduce
const personSchema = new mongoose.Schema(
{
name: { type: String, required: true },
},
{ timestamps: true }
);
const PersonModel = mongoose.model("Person", personSchema);
const person = new PersonModel({
name: "John",
});
await person.save();
// With `bulkWrite` it doesn't work
await PersonModel.bulkWrite([
{
updateOne: {
filter: { name: "John" },
update: {
createdAt: new Date(0),
},
options: {
timestamps: false,
overwriteImmutable: true,
},
},
},
]);
// Using `updateOne` directly it works
// await PersonModel.updateOne(
// { name: "John" },
// { createdAt: new Date(0) },
// { timestamps: false, overwriteImmutable: true }
// );
Expected Behavior
I expect to be able to override the createdAt field if needed.
Prerequisites
Mongoose version
7.x.x, 8.x.x
Node.js version
20.x
MongoDB server version
8.x
Typescript version (if applicable)
No response
Description
I'm trying to update the
createdAtfield of some documents usingbulkWriteand it's not possible. It works if I useupdateOnedirectly as a function but if I do it through abulkWriteit doesn't work.This only affects
createdAt,updatedAtcan be updated.So far I have tested it using Mongoose v7 and v8 and both have the same issue, I would appreciate it if this could be fixed in both versions 🙇🏽♂️.
Steps to Reproduce
Expected Behavior
I expect to be able to override the
createdAtfield if needed.