3

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.

kymmt
  • 75
  • 2
  • 9
  • What about keeping the length in seconds or milliseconds as an Integer? – Eric Dec 01 '12 at 08:34
  • Is that common way to do that? – kymmt Dec 01 '12 at 10:53
  • Yea @Eric s way is the normal way to do it, keep a timestamp from 0 based on the milisecond length of the file, this way it can be used with time functions and that quite easily. – Sammaye Dec 01 '12 at 11:05

1 Answers1

5

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.

Philipp
  • 67,764
  • 9
  • 118
  • 153