database – Database level operations

class mongotor.database.Database

Database object

classmethod connect(*args, **kwargs)

connect database

this method is deprecated, use init to initiate a new database

classmethod disconnect()

Disconnect to database

>>> Database.disconnect()
command(*args, **kwargs)

Issue a MongoDB command.

Send command command to the database and return the response. If command is an instance of basestring then the command {command: value} will be sent. Otherwise, command must be an instance of 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 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

  • **kwargs (optional): additional keyword arguments will be added to the command document before it is sent

Previous topic

API Reference

Next topic

collection – A mongo collection

This Page