Class: BSON::ObjectId

Inherits:
Object
  • Object
show all
Defined in:
build/mongoid-7.4/lib/mongoid/extensions.rb

Instance Method Summary collapse

Instance Method Details

#as_json(*args) ⇒ String

Return a string representation of the object id for use in application-level JSON serialization.

Examples:

Get the object id as a JSON-serializable object.

object_id.as_json

Returns:

  • (String)

    The object id as a string.



13
14
15
16
17
18
19
# File 'build/mongoid-7.4/lib/mongoid/extensions.rb', line 13

def as_json(*args)
  if Mongoid.object_id_as_json_oid
    { "$oid" => to_s }
  else
    bson_ruby_as_json(*args)
  end
end

#bson_ruby_as_jsonObject



4
# File 'build/mongoid-7.4/lib/mongoid/extensions.rb', line 4

alias :bson_ruby_as_json :as_json