【发布时间】:2022-01-17 07:24:12
【问题描述】:
几天来,我一直在努力让查询正常工作。目前我的模型如下所示:
class Geojson
include Mongoid::Document
field :type, type: String, default: 'Point'
field :coordinates, type: Array
index({coordinates: "2dsphere"}, { bits: 12})
end
以下查询返回 nil:
Geojson.find(:coordinates => {"$nearSphere" => [-70.1197340629727, 4.67071244438]})
这些是我数据库中的当前实例:
[#<Geojson _id: 61b7b21a9eb0c9ef0aa5626d, type: "Point", coordinates: [-74.13041168951031, 4.6638117]>,
#<Geojson _id: 61b7b2619eb0c9ef0aa5626e, type: "Point", coordinates: [-74.1213041168951, 4.5638117]>]
我可以在 mongosh 上毫无问题地查询类似的案例,但是我不确定直接在 rails 上做的错误在哪里。
【问题讨论】:
标签: ruby-on-rails ruby mongodb geojson mongo-shell