我有一个存储坐标的模型,并且坐标被索引
class Place
include Mongoid::Document
include Mongoid::Spacial::Document
field :coordinates, type: Array, spacial: true
index({ coordinates: "2d" }, { unique: true })
end
但是,每当我用一组坐标保存一个地方然后创建另一个时,两个坐标都会被保存。这使我相信坐标的索引不起作用。我在这里缺少什么,我该如何解决?
下面是一个例子。
place = Place.new(coordinates: [50, 50])
place.save # returns true in console
place2 = Place.new(coordinates: [50, 50])
place2.save # returns true in console
# Thus I have two place records with the same exact coordinates, something I don't want