class ApiKey
include Mongoid::Document
field :access_token, type: String
index({ access_token: 1}, { unique: true })
before_create :generate_access_token
private
def generate_access_token
begin
self.access_token = SecureRandom.hex
end