master_slave_connection – Master-slave connection to MongoDB

Master-Slave connection to Mongo.

Performs all writes to Master instance and distributes reads among all instances.

class pymongo.master_slave_connection.MasterSlaveConnection(master, slaves=[])

Create a new Master-Slave connection.

The resultant connection should be interacted with using the same mechanisms as a regular Connection. The Connection instances used to create this MasterSlaveConnection can themselves make use of connection pooling, etc. ‘Connection’ instances used as slaves should be created with the slave_okay option set to True.

Raises TypeError if master is not an instance of Connection or slaves is not a list of at least one Connection instances.

Parameters:
  • master: Connection instance for the writable Master
  • slaves (optional): list of Connection instances for the read-only slaves
close_cursor(cursor_id, connection_id)

Close a single database cursor.

Raises TypeError if cursor_id is not an instance of (int, long). What closing the cursor actually means depends on this connection’s cursor manager.

Parameters:
  • cursor_id: cursor id to close
  • connection_id: id of the Connection instance where the cursor was opened
database_names()
Get a list of all database names.
drop_database(name_or_database)

Drop a database.

Parameters:
  • name_or_database: the name of a database to drop or the object itself
end_request()

End the current “request”.

See documentation for Connection.end_request.

set_cursor_manager(manager_class)

Set the cursor manager for this connection.

Helper to set cursor manager for each individual Connection instance that make up this MasterSlaveConnection.

slave_okay

Is it okay for this connection to connect directly to a slave?

This is always True for MasterSlaveConnection instances.

start_request()

Start a “request”.

Start a sequence of operations in which order matters. Note that all operations performed within a request will be sent using the Master connection.

Previous topic

errors – Exceptions raised by the pymongo package

Next topic

code – Tools for representing JavaScript code to be evaluated by MongoDB

This Page