是否可以使用Rails 3更改MongoDB中的默认TimeZone? [英] Is it possible to change default TimeZone in MongoDB using Rails 3?

查看:115
本文介绍了是否可以使用Rails 3更改MongoDB中的默认TimeZone?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的麻烦:当我创建对象和设置一些datetime它是保存数据库在UTC TimeZone。这里是一个例子:

  //显示对象属性的完整列表
授权文件_id:5108ee29e6b564611400000,start_date:2013-01 -30 09:56:27 UTC
//然后显示a.start_date
星期三,2013年1月30日13:56:27 +0400

我试图禁止数据库使用UTC。这里是mongoid.yml:

 开发:
选项:
raise_not_found_error:false
会话:
默认值:
use_activesupport_time_zone:true
use_utc:false
数据库:test_mongoid_production
主机:
- 本地主机:27017
选项:
一致性::strong

和application.rb:

  config.time_zone ='莫斯科'

但是它不起作用。



有人可以帮忙解决这个问题吗?

解决方案

您可以更改应用程序的时区,以便ruby的日期对象将自动配置日期。 MongoDB将始终存储UTC时间。



MongoDB没有时区的内部知识。


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 ?

解决方案

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.

这篇关于是否可以使用Rails 3更改MongoDB中的默认TimeZone?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆