Let’s say I have a collection of subscriptions as below:
{
"id": "8SDQ8"
"durationInMonths": 12,
"startDate": {
"$date": "2020-07-03T09:14:46.609Z",
},
"endDate": {
"$date": "2021-07-03T09:14:46.609Z",
}
}
How can I add $durationInMonths to a variable date without being forced to fetch $durationInMonths beforehand ? Something like this:
const myDate = new Date();
subs.findOneAndUpdate({
id: '8SDQ8'
}, {
$set: {
startDate: myDate,
endDate: {
$addMonths(myDate, "$durationInMonths")
}
}
});