pymongo – Python driver for MongoDB

Python driver for MongoDB.

pymongo.version = '2.3'

Current version of PyMongo.

pymongo.Connection

Alias for pymongo.connection.Connection.

pymongo.ReplicaSetConnection

Alias for pymongo.replica_set_connection.ReplicaSetConnection.

class pymongo.read_preferences.ReadPreference

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

Connection to a single host:

  • PRIMARY: Queries are allowed if the connection is to the replica set primary.
  • PRIMARY_PREFERRED: Queries are allowed if the connection is to the primary or a secondary.
  • SECONDARY: Queries are allowed if the connection is to a secondary.
  • SECONDARY_PREFERRED: Same as PRIMARY_PREFERRED.
  • NEAREST: Same as PRIMARY_PREFERRED.

Connection 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.

ReplicaSetConnection:

  • 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.

Sub-modules:

Previous topic

tz_util – Utilities for dealing with timezones in Python

Next topic

connection – Tools for connecting to MongoDB

This Page