我正在使用 mongodb/mongoid 实现一个 ruby on rails 应用程序,我对更好的索引/搜索结构有点困惑。我staff
在模型中有一个字段,工作人员可以是任何一种类型 - 生产、经纪人、办公室。每个员工都是一个Person
。每种类型可以有多个员工。
所以我有两种方法:
1)。制作staff as an array
和储存它
[{:key => 'broker', :name => "Broker Name", :person_id => "654978"},
{:key => 'office', :name => "Office Staff 1", :person_id => "564654"},
{:key => 'office', :name => 'another office', :person_id => '79878'}]
2)。Make 是 aHash
并且 store 是 as
{:brokers => [{:person_id =>
2134, :name => 'Broker 1'}],
:office =>> [{:person_id =>
2131, :name => 'Office 1'}, {:person_id => 1231, :name => 'Office
2'}]}
我想为这些文档编制索引,并且应该能够搜索诸如 office = '465456' 之类的文档。