Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to change default TimeZone in MongoDB using Rails 3?

I have such trouble: when I'm creating object and setting some datetime It is saving database in UTC TimeZone. Here is example:

//showing full list of object properties 
 Grant _id: 5108ee29e6b564611400000, start_date: 2013-01-30 09:56:27 UTC
 //then showing a.start_date
 Wed, 30 Jan 2013 13:56:27 +0400 

I tried to forbid database to use UTC. Here is mongoid.yml:

development:
  options:
    raise_not_found_error: false
  sessions:
    default:
      use_activesupport_time_zone: true
      use_utc: false
      database: test_mongoid_production
      hosts:
        - localhost:27017
      options:
        consistency: :strong

and in application.rb:

config.time_zone = 'Moscow'

but it doesn't work.

Can someone help with this trouble ?

like image 943
deny7ko Avatar asked Oct 19 '25 17:10

deny7ko


1 Answers

You can change the timezone of your application so that ruby's date object will auto configure the dates. MongoDB will always store time in UTC.

MongoDB has no internal knowledge of timezones.

like image 93
Sammaye Avatar answered Oct 21 '25 08:10

Sammaye