Defining a different primary key in Mongomapper
I am defining a primary key in MongoMapper.
class B key :_id, string key :externalId, string end
The problem is that everything i add a new record in B, it appears that I need to explicity specify the _id, when it is already defined in the external id
B.new(:_id=>"123", :external_id=>"123 )
That does not quite make sense. There should be a way to specify externalId as the primary key, no?
If your problem is with BSON::ObjectId, I created a plugin that can help you, this plugin adds auto incremented id for MongoMapper documents
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