SequoiaDB
 All Classes Functions
Public Member Functions | List of all members
bson.objectid.ObjectId Class Reference
Inheritance diagram for bson.objectid.ObjectId:

Public Member Functions

def __init__
 
def from_datetime
 
def is_valid
 
def binary
 
def generation_time
 
def __getstate__
 
def __setstate__
 
def __str__
 
def __repr__
 
def __eq__
 
def __ne__
 
def __lt__
 
def __le__
 
def __gt__
 
def __ge__
 
def __hash__
 

Detailed Description

A ObjectId.

Constructor & Destructor Documentation

def bson.objectid.ObjectId.__init__ (   self,
  oid = None 
)
Initialize a new ObjectId. "oid" default None.

Parameters:
    Name     Type                 Info:
    oid      str/bytes/ObjectId   A valid ObjectId(12 byte binary
                                  or 24 character hex string or a
                                  ObjectId instance). default None.
                                  if "oid" is "None", "oid" will be
                                  generated internally.
                                  The structure of the "oid":
                                  first 4 bytes current time and
                                  3 bytesmachine and 2 bytes pid and
                                  3 bytes inc.
Exceptions:
    Type                         Info:
    TypeError.                   If "oid" is not instance of str,bytes
                                 or ObjectId, will raise "TypeError".
    bson.errors.InvalidId.       If "oid" is invalid, will raise
                                 "bson.errors.InvalidId".
For example:
    >>> from bson import ObjectId
    >>> ObjectId() # No parameter, mean "oid" is "None". will automatically generate a "oid"
    ObjectId('5d2c2af987abdf4f92f2f786')

    >>> ObjectId('5d2c2af987abdf4f92f2f786') # A 12 byte str parameter.
    ObjectId('5d2c2af987abdf4f92f2f786')

    >>> ObjectId(u'5d2c2af987abdf4f92f2f786') # A 24 character Unicode parameter.
    ObjectId('5d2c2af987abdf4f92f2f786')

Member Function Documentation

def bson.objectid.ObjectId.__getstate__ (   self)
return value of object for pickling.
needed explicitly because __slots__() defined.
def bson.objectid.ObjectId.__hash__ (   self)
Get a hash value for this :class:`ObjectId`.

.. versionadded:: 1.1
def bson.objectid.ObjectId.__setstate__ (   self,
  value 
)
explicit state set from pickling
def bson.objectid.ObjectId.binary (   self)
12-byte binary representation of this ObjectId.
def bson.objectid.ObjectId.from_datetime (   cls,
  generation_time 
)
Create a dummy ObjectId instance with a specific generation time.

This method is useful for doing range queries on a field
containing :class:`ObjectId` instances.

.. warning::
   It is not safe to insert a document containing an ObjectId
   generated using this method. This method deliberately
   eliminates the uniqueness guarantee that ObjectIds
   generally provide. ObjectIds generated with this method
   should be used exclusively in queries.

`generation_time` will be converted to UTC. Naive datetime
instances will be treated as though they already contain UTC.

An example using this helper to get documents where ``"_id"``
was generated before January 1, 2010 would be:

>>> gen_time = datetime.datetime(2010, 1, 1)
>>> dummy_id = ObjectId.from_datetime(gen_time)
>>> result = collection.find({"_id": {"$lt": dummy_id}})

:Parameters:
  - `generation_time`: :class:`~datetime.datetime` to be used
    as the generation time for the resulting ObjectId.

.. versionchanged:: 1.8
   Properly handle timezone aware values for
   `generation_time`.

.. versionadded:: 1.6
def bson.objectid.ObjectId.generation_time (   self)
A :class:`datetime.datetime` instance representing the time of
generation for this :class:`ObjectId`.

The :class:`datetime.datetime` is timezone aware, and
represents the generation time in UTC. It is precise to the
second.

.. versionchanged:: 1.8
   Now return an aware datetime instead of a naive one.

.. versionadded:: 1.2
def bson.objectid.ObjectId.is_valid (   cls,
  oid 
)
Checks if a `oid` string is valid or not.

:Parameters:
  - `oid`: the object id to validate

.. versionadded:: 2.3

The documentation for this class was generated from the following file: