Overriding default id in mongoid
Add the following field to your model:
field :_id, type: Moped::BSON::ObjectId
And to allow setting it:
1 def id=(id)
2 self[:_id] = id
3 end
Now you can just do obj.id=[Some ObjectId] and save the object.
field :_id, type: Moped::BSON::ObjectId
1 def id=(id)
2 self[:_id] = id
3 end
Comments