Hi How would I be able to convert millisecond to HH:MM:SS format in mongodb? Below is my sample data.
{
"Item":"Test1",
"millisecond" : 188760000
},
{
"Item":"Test2",
"millisecond" : 23280000
},
{
"Item":"Test3",
"millisecond" : 128820000
},
Expected output will be
{
"Item":"Test1",
"hrFormat" : 62:22:00
},
{
"Item":"Test2",
"millisecond" : 06:28:00
},
{
"Item":"Test3",
"millisecond" : 35:47:00
},
3
Answers
Converts a value to a date
toDate documentation mongodb
You could use
aggregate
and arithmetic operators:Link to playground.
Another solution is this one:
Be aware, it works only for times less than one year.
Mongo Playground