Denys Medynskyi
Denys Medynskyi

Reputation: 2353

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 ?

Upvotes: 4

Views: 19217

Answers (2)

Sammaye
Sammaye

Reputation: 43884

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.

Upvotes: 9

Sachin R
Sachin R

Reputation: 11876

config.time_zone doesn't set "Server Time", that is controlled by your operating system usually.

Rails always stores your dates in UTC in the database (unless you change a different setting).

Upvotes: 0

Related Questions