Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Saving date/time using mongomapper

Im trying to save date time information to the following field in mongo

key :last_comment_time_cache, DateTime

update_attributes!({:last_comment_time_cache => Time.now}) 

The data that is being saved is missing the time

"last_comment_time_cache": {
    "$date": "2013-03-23T00:00:00.000Z"
}

Any ideas on what im doing wrong?, Thanks Nath

like image 891
Nath Avatar asked Apr 14 '26 22:04

Nath


1 Answers

Try changing the field type to Time instead of DateTime. If you watch their Date extension here (Date is the parent of DateTime) they are only taking day,month and year into account to construct the date that will be sent to mongo, that's not the case for their Time implementation.

like image 152
fmendez Avatar answered Apr 17 '26 12:04

fmendez