My application uses Mongoose and has a schema that uses the timestamps option:
var fooSchema = new Schema({
name: String,
}, {
timestamps: true,
});
mongoose.model('Foo', fooSchema);
So whenever an update is written to the collection, the updatedAt
property is changed to the current date. But now I would like to add some changes that should not update the updatedAt
property.
Some answers on Stackoverflow (example) suggested to use Foo.collection
as that allegedly accesses the native MongoDB driver. So I tried this:
Foo.collection.update({ _id: someFooId }, { $set: { name: 'New Name' } });
However, that changed the updatedAt
property as well.
So how can I update a document, without changing updatedAt
?