I have similar documents as below in my collection.
[
{
“EventDetails”: [
{
“eventName”: “Music Fest”,
“key”: 1,
“startTime”: 1.618288532454e+12
},
{
“eventName”: “Music Concert”,
“key”: 2,
“startTime”: 1.514268532454e+12
}
],
“_id”: ObjectId(“5a934e000102030405000000”),
“name”: “Music Events”
},
{
“EventDetails”: [
{
“eventName”: “Book Fest”,
“key”: 1,
“startTime”: 1.618288532454e+12
},
{
“eventName”: “Book Show”,
“key”: 2,
“startTime”: 1.514268532454e+12
}
],
“_id”: ObjectId(“5a934e000102030405000001”),
“name”: “Book Events”
}
]
I want to convert all the startTime to date in my collection.
for rootlevel variables in my document I performed the below and it worked.
Query:
db.collection.updateMany({startTime:{$type:“long”}},[$set:{timestamp:{$toDate:“$timestamp”}}]).
How to update many and convert from number to date in all the nested arrays for Event Details.
Please update your post after reading
1 Like