MongoMapper - manually configuring an ObjectId with an "illegal ObjectID format"

I have a simple model object:

class UserRating
include MongoMapper::EmbeddedDocument       
key :idea_id, ObjectId
key :rating, Integer
end

I am trying to set Idea_Id on this object with: user_rating.idea_id = ObjectId.new

It throws: "illegal ObjectID format"

This seems like simple code ... The only thing I notice is ObjectID! = ObjectId. This may be a problem with the error message. Not sure. Very simple code. I don’t know why I cannot make it work. If this helps, this happens in the context of the Rails 3 Beta 4 project inside the Cucumber test. I successfully hit the mongodb daemon so that there is no strange connection problem. It would be very helpful if pointers.

+3
2

MongoMapper - ObjectId - BSON:: ObjectID, , mongodb.

, :

key :idea_id, BSON::ObjectID, :index => true
+3

, ObjectId. , , .

user_rating.idea_id = idea.id

+2

Source: https://habr.com/ru/post/1757757/


All Articles