I have my mongoose schema defined as follows.
mongoose.Schema({
"url": String,
"translations": [
{
"targetLang": String,
"source": String,
"target": String
}
],
}, { versionKey: false });
I updated my schema to include createdAt
and updatedAt
with the new schema looking as:
mongoose.Schema({
"url": String,
"translations": [
{
"targetLang": String,
"source": String,
"target": String,
"createdAt": { type: Date, default: Date.now },
"updatedAt": { type: Date, default: Date.now }
}
],
}, { versionKey: false });
So when new documents are created, the createdAt
and updatedAt
is auto-populated, as expected. How can I have the old documents with the new key createdAt
and updatedAt
. Is there any way?
Note: I am okay with the old documents to have the current or any previous date. But I want all of them to have a date.