pymongo – Python driver for MongoDB — PyMongo 2.7.2 documentation

# `pymongo` – Python driver for MongoDB

Python driver for MongoDB.

`pymongo.` `version` = '2.7.2'

  Current version of PyMongo.

`pymongo.` `MongoClient`

  Alias for `pymongo.mongo_client.MongoClient`.

`pymongo.` `MongoReplicaSetClient`

  Alias for `pymongo.mongo_replica_set_client.MongoReplicaSetClient`.

class `pymongo.read_preferences.` `ReadPreference`

  An enum that defines the read preference modes supported by PyMongo. Used in three cases:

  `MongoClient` connected to a single host:

  - PRIMARY: Queries are allowed if the host is standalone or the replica set primary.
  - All other modes allow queries to standalone servers, to the primary, or to secondaries.

  `MongoClient` connected to a mongos, with a sharded cluster of replica sets:

  - PRIMARY: Queries are sent to the primary of a shard.
  - PRIMARY_PREFERRED: Queries are sent to the primary if available, otherwise a secondary.
  - SECONDARY: Queries are distributed among shard secondaries. An error is raised if no secondaries are available.
  - SECONDARY_PREFERRED: Queries are distributed among shard secondaries, or the primary if no secondary is available.
  - NEAREST: Queries are distributed among all members of a shard.

  `MongoReplicaSetClient`:

  - PRIMARY: Queries are sent to the primary of the replica set.
  - PRIMARY_PREFERRED: Queries are sent to the primary if available, otherwise a secondary.
  - SECONDARY: Queries are distributed among secondaries. An error is raised if no secondaries are available.
  - SECONDARY_PREFERRED: Queries are distributed among secondaries, or the primary if no secondary is available.
  - NEAREST: Queries are distributed among all members.

`pymongo.` `has_c`()

  Is the C extension installed?

  New in version 1.5.

`pymongo.` `MIN_SUPPORTED_WIRE_VERSION`

  The minimum wire protocol version PyMongo supports.

`pymongo.` `MAX_SUPPORTED_WIRE_VERSION`

  The maximum wire protocol version PyMongo supports.

Sub-modules:

- `connection` – Tools for connecting to MongoDB
- `database` – Database level operations
- `collection` – Collection level operations
- `command_cursor` – Tools for iterating over MongoDB command results
- `cursor` – Tools for iterating over MongoDB query results
- `bulk` – The bulk write operations interface
- `errors` – Exceptions raised by the `pymongo` package
- `master_slave_connection` – Master-slave connection to MongoDB
- `message` – Tools for creating messages to be sent to MongoDB
- `mongo_client` – Tools for connecting to MongoDB
- `mongo_replica_set_client` – Tools for connecting to a MongoDB replica set
- `pool` – Pool module for use with a MongoDB client.
- `replica_set_connection` – Tools for connecting to a MongoDB replica set
- `son_manipulator` – Manipulators that can edit SON documents as they are saved or retrieved
- `cursor_manager` – Managers to handle when cursors are killed after being closed – DEPRECATED
- `uri_parser` – Tools to parse and validate a MongoDB URI