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

孤街浪徒 提交于 2019-12-22 23:20:23

问题


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 ?


回答1:


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.




回答2:


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).



来源:https://stackoverflow.com/questions/14601283/is-it-possible-to-change-default-timezone-in-mongodb-using-rails-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!