我在初始化程序 mongo_config.rb 中寻找一种方法来为位置创建索引。换句话说,我希望能够做到
db.map.ensureIndex({"gps": "2d"})
在初始化器和 ruby 中。我该怎么做?
最佳答案
参见 MongoDB Ruby Documentation .你想要 ensure_index
,例如 map.ensure_index([["gps", Mongo::GEO2D]])
会做你想做的,假设 map
是一个 Mongo::Collection
。
关于ruby-on-rails - MongoDB 和 Rails : How to create Index,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8773932/