有没有办法为mongomapper创建人类可读的id
我的意思是将54114ac51d41c84fb900005a
替换为id 1
由于
答案 0 :(得分:0)
尝试:
这是MongoMapper的插件,可以在MongoMapper的文档中添加auto incremented ids
。
示例:
# app/models/movie.rb
class Movie
include MongoMapper::Document
key :title, String
# Here is the mongomapper_id2
auto_increment!
end
movie = Movie.create(:title => 'The Simpsons Movie')
movie.id # BSON::ObjectId('4d1d150d30f2246bc6000001')
# Here is the mongomapper_id2
movie.id2
# => 1
movie2 = Movie.create(:title => 'Pirates of Silicon Valley')
movie2.id2
# => 2