pymongo::database::Database Class Reference

List of all members.

Public Member Functions

def __call__
def __cmp__
def __getattr__
def __getitem__
def __init__
def __iter__
def __repr__
def add_son_manipulator
def add_user
def authenticate
def collection_names
def command
def connection
def create_collection
def dereference
def drop_collection
def error
def eval
def last_status
def logout
def name
def next
def previous_error
def profiling_info
def profiling_level
def remove_user
def reset_error_history
def set_profiling_level
def system_js
def validate_collection

Private Member Functions

def _fix_incoming
def _fix_outgoing

Private Attributes

 __connection
 __incoming_copying_manipulators
 __incoming_manipulators
 __name
 __outgoing_copying_manipulators
 __outgoing_manipulators
 __system_js

Detailed Description

A Mongo database.

Definition at line 42 of file database.py.


Member Function Documentation

def pymongo::database::Database::__call__ (   self,
  args,
  kwargs 
)
This is only here so that some API misusages are easier to debug.

Definition at line 573 of file database.py.

def pymongo::database::Database::__cmp__ (   self,
  other 
)

Definition at line 128 of file database.py.

def pymongo::database::Database::__getattr__ (   self,
  name 
)
Get a collection of this database by name.

Raises InvalidName if an invalid collection name is used.

:Parameters:
  - `name`: the name of the collection to get

Definition at line 137 of file database.py.

def pymongo::database::Database::__getitem__ (   self,
  name 
)
Get a collection of this database by name.

Raises InvalidName if an invalid collection name is used.

:Parameters:
  - `name`: the name of the collection to get

Definition at line 147 of file database.py.

def pymongo::database::Database::__init__ (   self,
  connection,
  name 
)
Get a database by connection and name.

Raises :class:`TypeError` if `name` is not an instance of
:class:`basestring`. Raises
:class:`~pymongo.errors.InvalidName` if `name` is not a valid
database name.

:Parameters:
  - `connection`: a :class:`~pymongo.connection.Connection`
    instance
  - `name`: database name

.. mongodoc:: databases

Definition at line 46 of file database.py.

def pymongo::database::Database::__iter__ (   self  ) 

Definition at line 424 of file database.py.

def pymongo::database::Database::__repr__ (   self  ) 

Definition at line 134 of file database.py.

def pymongo::database::Database::_fix_incoming (   self,
  son,
  collection 
) [private]
Apply manipulators to an incoming SON object before it gets stored.

:Parameters:
  - `son`: the son object going into the database
  - `collection`: the collection the son object is being saved in

Definition at line 198 of file database.py.

def pymongo::database::Database::_fix_outgoing (   self,
  son,
  collection 
) [private]
Apply manipulators to a SON object as it comes out of the database.

:Parameters:
  - `son`: the son object coming out of the database
  - `collection`: the collection the son object was saved in

Definition at line 211 of file database.py.

def pymongo::database::Database::add_son_manipulator (   self,
  manipulator 
)
Add a new son manipulator to this database.

Newly added manipulators will be applied before existing ones.

:Parameters:
  - `manipulator`: the manipulator to add

Definition at line 76 of file database.py.

def pymongo::database::Database::add_user (   self,
  name,
  password 
)
Create user `name` with password `password`.

Add a new user with permissions for this :class:`Database`.

.. note:: Will change the password if user `name` already exists.

:Parameters:
  - `name`: the name of the user to create
  - `password`: the password of the user to create

.. versionadded:: 1.4

Definition at line 430 of file database.py.

def pymongo::database::Database::authenticate (   self,
  name,
  password 
)
Authenticate to use this database.

Once authenticated, the user has full read and write access to
this database. Raises :class:`TypeError` if either `name` or
`password` is not an instance of ``(str,
unicode)``. Authentication lasts for the life of the database
connection, or until :meth:`logout` is called.

The "admin" database is special. Authenticating on "admin"
gives access to *all* databases. Effectively, "admin" access
means root access to the database.

.. note:: Currently, authentication is per
   :class:`~socket.socket`. This means that there are a couple
   of situations in which re-authentication is necessary:

   - On failover (when an
     :class:`~pymongo.errors.AutoReconnect` exception is
     raised).

   - After a call to
     :meth:`~pymongo.connection.Connection.disconnect` or
     :meth:`~pymongo.connection.Connection.end_request`.

   - When sharing a :class:`~pymongo.connection.Connection`
     between multiple threads, each thread will need to
     authenticate separately.

.. warning:: Currently, calls to
   :meth:`~pymongo.connection.Connection.end_request` will
   lead to unpredictable behavior in combination with
   auth. The :class:`~socket.socket` owned by the calling
   thread will be returned to the pool, so whichever thread
   uses that :class:`~socket.socket` next will have whatever
   permissions were granted to the calling thread.

:Parameters:
  - `name`: the name of the user to authenticate
  - `password`: the password of the user to authenticate

.. mongodoc:: authenticate

Definition at line 462 of file database.py.

def pymongo::database::Database::collection_names (   self  ) 
Get a list of all the collection names in this database.

Definition at line 297 of file database.py.

def pymongo::database::Database::command (   self,
  command,
  value = 1,
  check = True,
  allowable_errors = [],
  kwargs 
)
Issue a MongoDB command.

Send command `command` to the database and return the
response. If `command` is an instance of :class:`basestring`
then the command {`command`: `value`} will be sent. Otherwise,
`command` must be an instance of :class:`dict` and will be
sent as is.

Any additional keyword arguments will be added to the final
command document before it is sent.

For example, a command like ``{buildinfo: 1}`` can be sent
using:

>>> db.command("buildinfo")

For a command where the value matters, like ``{collstats:
collection_name}`` we can do:

>>> db.command("collstats", collection_name)

For commands that take additional arguments we can use
kwargs. So ``{filemd5: object_id, root: file_root}`` becomes:

>>> db.command("filemd5", object_id, root=file_root)

:Parameters:
  - `command`: document representing the command to be issued,
    or the name of the command (for simple commands only).

    .. note:: the order of keys in the `command` document is
       significant (the "verb" must come first), so commands
       which require multiple keys (e.g. `findandmodify`)
       should use an instance of :class:`~bson.son.SON` or
       a string and kwargs instead of a Python `dict`.

  - `value` (optional): value to use for the command verb when
    `command` is passed as a string
  - `check` (optional): check the response for errors, raising
    :class:`~pymongo.errors.OperationFailure` if there are any
  - `allowable_errors`: if `check` is ``True``, error messages
    in this list will be ignored by error-checking
  - `**kwargs` (optional): additional keyword arguments will
    be added to the command document before it is sent

.. versionchanged:: 1.6
   Added the `value` argument for string commands, and keyword
   arguments for additional command options.
.. versionchanged:: 1.5
   `command` can be a string in addition to a full document.
.. versionadded:: 1.4

.. mongodoc:: commands

Definition at line 224 of file database.py.

def pymongo::database::Database::connection (   self  ) 
The :class:`~pymongo.connection.Connection` instance for this
:class:`Database`.

.. versionchanged:: 1.3
   ``connection`` is now a property rather than a method.

Definition at line 110 of file database.py.

def pymongo::database::Database::create_collection (   self,
  name,
  options = None,
  kwargs 
)
Create a new :class:`~pymongo.collection.Collection` in this
database.

Normally collection creation is automatic. This method should
only be used to specify options on
creation. :class:`~pymongo.errors.CollectionInvalid` will be
raised if the collection already exists.

Options should be passed as keyword arguments to this
method. Any of the following options are valid:

  - "size": desired initial size for the collection (in
    bytes). must be less than or equal to 10000000000. For
    capped collections this size is the max size of the
    collection.
  - "capped": if True, this is a capped collection
  - "max": maximum number of objects if capped (optional)

:Parameters:
  - `name`: the name of the collection to create
  - `options`: DEPRECATED options to use on the new collection
  - `**kwargs` (optional): additional keyword arguments will
    be passed as options for the create collection command

.. versionchanged:: 1.5
   deprecating `options` in favor of kwargs

Definition at line 157 of file database.py.

def pymongo::database::Database::dereference (   self,
  dbref 
)
Dereference a :class:`~bson.dbref.DBRef`, getting the
document it points to.

Raises :class:`TypeError` if `dbref` is not an instance of
:class:`~bson.dbref.DBRef`. Returns a document, or ``None`` if
the reference does not point to a valid document.  Raises
:class:`ValueError` if `dbref` has a database specified that
is different from the current database.

:Parameters:
  - `dbref`: the reference

Definition at line 526 of file database.py.

def pymongo::database::Database::drop_collection (   self,
  name_or_collection 
)
Drop a collection.

:Parameters:
  - `name_or_collection`: the name of a collection to drop or the
    collection object itself

Definition at line 307 of file database.py.

def pymongo::database::Database::error (   self  ) 
Get a database error if one occured on the last operation.

Return None if the last operation was error-free. Otherwise return the
error that occurred.

Definition at line 384 of file database.py.

def pymongo::database::Database::eval (   self,
  code,
  args 
)
Evaluate a JavaScript expression in MongoDB.

Useful if you need to touch a lot of data lightly; in such a
scenario the network transfer of the data could be a
bottleneck. The `code` argument must be a JavaScript
function. Additional positional arguments will be passed to
that function when it is run on the server.

Raises :class:`TypeError` if `code` is not an instance of
(str, unicode, `Code`). Raises
:class:`~pymongo.errors.OperationFailure` if the eval
fails. Returns the result of the evaluation.

:Parameters:
  - `code`: string representation of JavaScript code to be
    evaluated
  - `args` (optional): additional positional arguments are
    passed to the `code` being evaluated

Definition at line 547 of file database.py.

def pymongo::database::Database::last_status (   self  ) 
Get status information from the last operation.

Returns a SON object with status information.

Definition at line 397 of file database.py.

def pymongo::database::Database::logout (   self  ) 
Deauthorize use of this database for this connection.

Note that other databases may still be authorized.

Definition at line 519 of file database.py.

def pymongo::database::Database::name (   self  ) 
The name of this :class:`Database`.

.. versionchanged:: 1.3
   ``name`` is now a property rather than a method.

Definition at line 120 of file database.py.

def pymongo::database::Database::next (   self  ) 

Definition at line 427 of file database.py.

def pymongo::database::Database::previous_error (   self  ) 
Get the most recent error to have occurred on this database.

Only returns errors that have occurred since the last call to
`Database.reset_error_history`. Returns None if no such errors have
occurred.

Definition at line 404 of file database.py.

def pymongo::database::Database::profiling_info (   self  ) 
Returns a list containing current profiling information.

.. mongodoc:: profiling

Definition at line 377 of file database.py.

def pymongo::database::Database::profiling_level (   self  ) 
Get the database's current profiling level.

Returns one of (:data:`~pymongo.OFF`,
:data:`~pymongo.SLOW_ONLY`, :data:`~pymongo.ALL`).

.. mongodoc:: profiling

Definition at line 347 of file database.py.

def pymongo::database::Database::remove_user (   self,
  name 
)
Remove user `name` from this :class:`Database`.

User `name` will no longer have permissions to access this
:class:`Database`.

:Parameters:
  - `name`: the name of the user to remove

.. versionadded:: 1.4

Definition at line 449 of file database.py.

def pymongo::database::Database::reset_error_history (   self  ) 
Reset the error history of this database.

Calls to `Database.previous_error` will only return errors that have
occurred since the most recent call to this method.

Definition at line 416 of file database.py.

def pymongo::database::Database::set_profiling_level (   self,
  level 
)
Set the database's profiling level.

Raises :class:`ValueError` if level is not one of
(:data:`~pymongo.OFF`, :data:`~pymongo.SLOW_ONLY`,
:data:`~pymongo.ALL`).

:Parameters:
  - `level`: the profiling level to use

.. mongodoc:: profiling

Definition at line 360 of file database.py.

def pymongo::database::Database::system_js (   self  ) 
A :class:`SystemJS` helper for this :class:`Database`.

See the documentation for :class:`SystemJS` for more details.

.. versionadded:: 1.5

Definition at line 100 of file database.py.

def pymongo::database::Database::validate_collection (   self,
  name_or_collection 
)
Validate a collection.

Returns a string of validation info. Raises CollectionInvalid if
validation fails.

Definition at line 326 of file database.py.


Member Data Documentation

Definition at line 67 of file database.py.

Definition at line 70 of file database.py.

Definition at line 69 of file database.py.

Definition at line 66 of file database.py.

Definition at line 72 of file database.py.

Definition at line 71 of file database.py.

Definition at line 74 of file database.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:06 2013