When a Mongoose schema has timestamps: true, Mongoose automatically manages createdAt and updatedAt. This becomes a problem if you’re explicitly setting updatedAt to a specific value in a findOneAndUpdate call — Mongoose silently overrides your value with the time of the DB write.

// updatedAt will be set to "now" (DB write time), not pollStartTime
await CounterModel.findOneAndUpdate(
    { _id: COUNTER_TYPE.VOLTNET_LAST_POLL },
    { $set: { updatedAt: pollStartTime } },
    { upsert: true }
)

Fix: pass { timestamps: false } in the options to disable automatic timestamp management for that call.

await CounterModel.findOneAndUpdate(
    { _id: COUNTER_TYPE.VOLTNET_LAST_POLL },
    { $set: { updatedAt: pollStartTime } },
    { upsert: true, timestamps: false }
)

Warning

Mongoose silently overwrites explicit updatedAt values — if you’re storing a domain timestamp (not “now”) in a field named updatedAt, always pass { timestamps: false }.