【发布时间】:2014-05-10 06:29:06
【问题描述】:
我是 MongoID 的新手。我有以下型号:
class Vehicle
include Mongoid::Document
include Mongoid::Timestamps
##
# Relationship
embeds_one :specification
end
class Specification
include Mongoid::Document
##
# Columns
field :body, type: String
##
# Relationship
embedded_in :vehicle
end
在我的控制器中,我尝试在 body 的 specification /embed document/ 字段中使用 $in 运算符。如何在嵌入文档中使用$in 运算符?我尝试了下面的代码,但它不起作用。
result += Vehicle.where(:specification.matches => { :body.in => param(:body) }) if params[:body].present?
感谢您的帮助:)
【问题讨论】:
-
我不确定你想在这里做什么,但
embeds_one只是一堆嵌入哈希的包装,所以Vehicle.where('specification.body' => ...)可能是一个起点。
标签: ruby-on-rails mongodb ruby-on-rails-4 mongoid mongoid3