我正在尝试使用空间索引查询文档。
根据文档,我的模型看起来像:
class Trip
include Mongoid::Document
field :addresses, :type => Array
index({"addresses.loc" => "2d"}, {:min => -180, :max => 180})
end
地址是这样存储的
Trip.first.addresses
=> [{"context"=>"from", "loc"=>[-71.55234, -33.024527]}, {"context"=>"to", "loc"=>[-70.641997, -33.4691199]}]
我想使用以下查询查询与 address.loc 和 address.context 匹配的文档:
Trip.where("addresses.loc" => {"$nearSphere" => [-70.641997, -33.4691199], "$maxDistance" => 0.005052092295133236}).where("addresses.context" => "to")
查询返回正确的值,但似乎忽略了“address.context”。我做的正确吗?
谢谢 !