Class | BSON::ObjectId |
In: |
lib/bson/types/object_id.rb
|
Parent: | Object |
Generates MongoDB object ids.
data | [RW] |
Adds a primary key to the given document if needed.
@param [Hash] doc a document requiring an _id.
@return [BSON::ObjectId, Object] returns a newly-created or
current _id for the given document.
Given a string representation of an ObjectId, return a new ObjectId with that value.
@param [String] str
@return [BSON::ObjectId]
Create an object id from the given time. This is useful for doing range queries; it works because MongoDB‘s object ids begin with a timestamp.
@param [Time] time a utc time to encode as an object id.
@option opts [:unique] (false) If false, the object id‘s bytes
succeeding the timestamp will be zeroed; if true, they'll consist of the standard machine id, pid, and counter.
@return [BSON::ObjectId]
@example Return all document created before Jan 1, 2010.
time = Time.utc(2010, 1, 1) time_id = ObjectId.from_time(time) collection.find({'_id' => {'$lt' => time_id}})
Determine if the supplied string is legal. Legal strings will consist of 24 hexadecimal characters.
@param [String] str
@return [Boolean]
Create a new object id. If no parameter is given, an id corresponding to the ObjectId BSON data type will be created. This is a 12-byte value consisting of a 4-byte timestamp, a 3-byte machine id, a 2-byte process id, and a 3-byte counter.
@param [Array] data should be an array of bytes. If you want
to generate a standard MongoDB object id, leave this argument blank.
@option opts :data (nil) An array of bytes to use as the object id. @option opts :time (nil) The value of this object ids timestamp. Note that
the remaining bytes will consist of the standard machine id, pid, and counter. If you need a zeroed timestamp, used ObjectId.from_time.
Return the UTC time at which this ObjectId was generated. This may be used in lieu of a created_at timestamp since this information is always encoded in the object id.
@return [Time] the time at which this object was created.
Get a unique hashcode for this object. This is required since we‘ve defined an eql? method.
@return [Integer]
Convert to MongoDB extended JSON format. Since JSON includes type information, but lacks an ObjectId type, this JSON format encodes the type using an $oid key.
@return [String] the object id represented as MongoDB extended JSON.