【问题标题】:_type field is excluded in mongo when doing to_json执行 to_json 时 _type 字段在 mongo 中被排除
【发布时间】:2011-11-15 08:41:02
【问题描述】:

我正在使用 mongo db,但在调用 to_json 方法时遇到了一个奇怪的问题。 假设我有一个模型站。现在我可以在使用 Station.first 时看到 _type 属性,甚至在使用 Station.first.to_json(:only => [:_type]) 转换为 json 时也可以看到该属性 但问题只是简单地做 ` Station.first.to_json ' 只是排除了 _type 属性,但很好地显示了其他属性。你们能帮我解决这个问题吗?

我正在使用 rails 3.1.1 和 mongoid 2.3.3

【问题讨论】:

  • 在 rails 3.0 和 mongoid 2.2.3 中运行良好

标签: ruby-on-rails-3.1 mongoid


【解决方案1】:

使用Station.first.to_json(:methods => :_type)

【讨论】:

  • 按预期工作。我正在使用as_json(:methods => [:_type])
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多