bson::objectid::ObjectId Class Reference

List of all members.

Public Member Functions

def __cmp__
def __hash__
def __init__
def __repr__
def __str__
def binary
def from_datetime
def generation_time

Private Member Functions

def __generate
def __validate

Private Attributes

 __id

Static Private Attributes

tuple __slots__ = ('__id')
int _inc = 0
tuple _inc_lock = threading.Lock()
tuple _machine_bytes = _machine_bytes()

Detailed Description

A MongoDB ObjectId.

Definition at line 45 of file bson/objectid.py.


Member Function Documentation

def bson::objectid::ObjectId::__cmp__ (   self,
  other 
)

Definition at line 196 of file bson/objectid.py.

def bson::objectid::ObjectId::__generate (   self  )  [private]
Generate a new value for this ObjectId.

Definition at line 120 of file bson/objectid.py.

def bson::objectid::ObjectId::__hash__ (   self  ) 
Get a hash value for this :class:`ObjectId`.

.. versionadded:: 1.1

Definition at line 201 of file bson/objectid.py.

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

If `oid` is ``None``, create a new (unique) ObjectId. If `oid`
is an instance of (``basestring``, :class:`ObjectId`) validate
it and use that.  Otherwise, a :class:`TypeError` is
raised. If `oid` is invalid,
:class:`~bson.errors.InvalidId` is raised.

:Parameters:
  - `oid` (optional): a valid ObjectId (12 byte binary or 24 character
    hex string)

.. versionadded:: 1.2.1
   The `oid` parameter can be a ``unicode`` instance (that contains
   only hexadecimal digits).

.. mongodoc:: objectids

Definition at line 56 of file bson/objectid.py.

def bson::objectid::ObjectId::__repr__ (   self  ) 

Definition at line 193 of file bson/objectid.py.

def bson::objectid::ObjectId::__str__ (   self  ) 

Definition at line 190 of file bson/objectid.py.

def bson::objectid::ObjectId::__validate (   self,
  oid 
) [private]
Validate and use the given id for this ObjectId.

Raises TypeError if id is not an instance of (str, ObjectId) and
InvalidId if it is not a valid ObjectId.

:Parameters:
  - `oid`: a valid ObjectId

Definition at line 142 of file bson/objectid.py.

def bson::objectid::ObjectId::binary (   self  ) 
12-byte binary representation of this ObjectId.

Definition at line 168 of file bson/objectid.py.

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

Definition at line 81 of file bson/objectid.py.

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

Definition at line 174 of file bson/objectid.py.


Member Data Documentation

Definition at line 140 of file bson/objectid.py.

tuple bson::objectid::ObjectId::__slots__ = ('__id') [static, private]

Definition at line 54 of file bson/objectid.py.

int bson::objectid::ObjectId::_inc = 0 [static, private]

Definition at line 49 of file bson/objectid.py.

tuple bson::objectid::ObjectId::_inc_lock = threading.Lock() [static, private]

Definition at line 50 of file bson/objectid.py.

Definition at line 52 of file bson/objectid.py.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines


pymongo
Author(s): Bhaskara Marthi
autogenerated on Fri Jan 11 10:09:05 2013