Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What type to store time length with Mongo

What type should i use to store time length with MongoDB?

I need to store time length of sound data. so Timestamp type doesn't seem right.

like image 478
kymmt Avatar asked Dec 13 '25 10:12

kymmt


1 Answers

You should use an integer for that.

MongoDB has two data types especially for timekeeping: Date and Timestamp. But these are meant to represent a specific point in time. They aren't suitable for expressing durations (also, timestamp is for internal use. Users are discouraged from using it).

So your best bet is to convert the duration into milliseconds and store this value in the database.

like image 88
Philipp Avatar answered Dec 15 '25 05:12

Philipp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!