【发布时间】:2011-10-03 02:13:18
【问题描述】:
我有一个模型如下:
class City
include Mongoid::Document
field :name
embeds_many :stores
index [["stores.location", Mongoid::GEO2D]]
end
class Store
include Mongoid::Document
field :name
field :location, :type => Array
embedded_in :cities, :inverse_of => :stores
end
然后我尝试拨打类似City.stores.near(@location) 的电话。
我想查询City 集合以返回附近位置至少有1 个Store 的所有城市。我应该如何设置索引?最快的调用是什么?
我使用 index [[:location, Mongo::GEO2D]] 阅读了 Mongoid 文档,但我不确定这如何应用于嵌入式文档,或者如何仅获取 City 而不是所有 Stop 文档。
【问题讨论】:
标签: ruby-on-rails ruby mongodb mongoid