Reputation: 17629
I was looking for a way in the initializer mongo_config.rb to create an index for locations. In other words, I want to be able to do
db.map.ensureIndex({"gps" : "2d"})
in the initializer and in ruby. How do I do this?
Upvotes: 2
Views: 3370
Reputation: 19181
Updated example: map.indexes.create_one({some_key: 1}, {unique: true})
(also assuming map
is a Mongo::Collection
)
Upvotes: 2
Reputation: 4520
See MongoDB Ruby Documentation. You want ensure_index
, for example map.ensure_index([["gps", Mongo::GEO2D]])
will do what you want, assuming map
is a Mongo::Collection
.
Upvotes: 5