「CEO」という役職が少なくとも 1 つあるすべての企業をプルしたいと考えています。
各テーブルと交差のクエリと一緒にハックすることができました(私は知っています...結合はありませんhttp://mongoid.org/en/mongoid/docs/tips.html#relational_associations、およびmongoid の N+1 問題、会社にポジションを埋め込むこともできます)が、次のようなことを行う方法は次のとおりです。
Company.includes(:positions).where("positions.title" => "CEO")?
ありがとう:
class Position
include Mongoid::Document
field :title, type: String
field :profile_id, type: String
field :tenure, type: BigDecimal
belongs_to :company, index: true
class Company
include Mongoid::Document
field :name, type: String
field :linkedin_id, type: String
field :positions_count, type: Integer #Mongo Index
belongs_to :industry, index: true
has_many :positions
index({ positions_count: 1}, {background: true})