【发布时间】:2013-07-11 22:14:42
【问题描述】:
我有一个存储坐标的模型,并且坐标是索引的
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
【问题讨论】:
-
你能举个例子吗?
-
把它放在我的问题中。
标签: ruby mongodb indexing sinatra mongoid