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?

Answers


If your problem is with BSON::ObjectId, I created a plugin that can help you, this plugin adds auto incremented id for MongoMapper documents

https://github.com/phstc/mongomapper_id2

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

Need Your Help

Python Thread that runs at the start of every minute

python multithreading

Hi there i need to implement a thread which runs at the beggining of every minute. The execution flow should look like this.

Is there an editor for 4DOS btm files that support syntax highlighting and indentation?

windows syntax-highlighting text-editor indentation

I'm reverse engineering a customer's .btm file (currently using Win7). Can I hope to find a text editor (or a Netbeans plugin) that supports indentation and syntax highlighting?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.