MongoDB scripting is still pretty cryptic to me, and stuck with this problem on a 3.6 server lacking the fancier operators from 4.2.
How to increase a date field with one second value in a MongoDB 3.6?
For example, I'd like to do something like this:
db.getCollection("therecords").update(
{
"_id" : ObjectId("123etc")
},
{
$set: {
updatedAt : "$updatedAt" + 1 ;
}
}
);
…will set the value to the text $updatedAt1
which is cute.
Other cute errors are thrown when using updatedAt
without quotes or without the $ prefix.
More generically, is there a way to reuse current values with update … $set
?
I don't think it is possible to do this using single query in MongoDB v3.6, but:
find()
specific documentsforEach()
found document, get the date and bumpsave()
it back