db.collection.updateOne({
someId: "myId",
},
{
$set: {
startDate: {
$subtract: ["$startDate", 18000000] // this is 5 hours in ms
},
endDate: {
$add: ["$endDate", 18000000]
}
}
})
Above is the current code I have, with a few name changes. I want to know how I can update the doc's startDate and endDate fields with subtraction and addition, but when I run this I don't get any changes.
I have checked the documentation, and I can't use $dateAdd because I'm on 4.4.12 and that requires 5.0; also in the updateOne documentation I don't see any examples with addition or subtraction.
I've also gotten the error:
The dollar ($) prefixed field '$add' in 'endDate.$add' is not valid for storage.
when trying to do it this way. I tried using $update even though that's deprecated, but that obviously didn't work.
Does anyone see any glaring issues, or have a recommendation of how to solve this?