pymongo – Python driver for MongoDB

Python driver for MongoDB.

pymongo.version = '2.7.1'

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:

Previous topic

tz_util – Utilities for dealing with timezones in Python

Next topic

connection – Tools for connecting to MongoDB

This Page