Best way to store only 'time' in MongoDB?

4,007 views
Skip to first unread message

Charlie

unread,
May 27, 2011, 1:21:52 PM5/27/11
to mongodb-user
What I'm trying to store is time, e.g. '10:00', '17:00' etc. So the
date doesn't matter.

What's the best way to store this in Mongo? The options I've come up
with so far are:

- Date object (and just ignore the date aspect of it)

Charlie

unread,
May 27, 2011, 1:24:28 PM5/27/11
to mongodb-user
Oops, hit send by accident.

So options are:
- Date object (and just ignore the date aspect of it)
- Minutes (or seconds/milliseconds) since midnight.

I'm leaning towards minutes or seconds at the moment because it should
be more efficient on space, while still providing an easy way of doing
comparisons ($gt, $lt). Plus it remains easy to turn into a Date
object in whatever language is being used.

Has anyone had experience or suggestions on this?

Thanks

Sam Millman

unread,
May 27, 2011, 1:31:28 PM5/27/11
to mongod...@googlegroups.com
"I'm leaning towards minutes or seconds at the moment because it should
be more efficient on space, while still providing an easy way of doing
comparisons ($gt, $lt)"

It wont be easy since your proposed structure is "10:00" which is a string. If you stored time() (UTC stamp) since midnight then yes but then that would use up the same amount of space as a time object which would render that whole argument pointless.

I would say just go with the way Mongo is designed and go with a datetime object. Trying to work around it could actually leave you with a worse system as stated above.

--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.


Martin Wawrusch

unread,
May 27, 2011, 1:38:02 PM5/27/11
to mongod...@googlegroups.com
I'd choose minutes for this. Keeps the data model clearer, and the math involved is trivial

Reply all
Reply to author
Forward
0 new messages