Changes in Version 2.2

Version 2.2 adds a few more frequently requested features and fixes a number of bugs.

Special thanks go to Alex Grönholm for his contributions to Python 3 support and maintaining the original pymongo3 port. Christoph Simon, Wouter Bolsterlee, Mike O’Brien, and Chris Tompkinson also contributed to this release.

Important New Features:

  • Support for Python 3 - See the Python 3 FAQ for more information.
  • Support for Gevent - See Gevent for more information.
  • Improved connection pooling - See Requests for more information.


A number of methods and method parameters that were deprecated in PyMongo 1.9 or older versions have been removed in this release. The full list of changes can be found in the following JIRA ticket:

BSON module aliases from the pymongo package that were deprecated in PyMongo 1.9 have also been removed in this release. See the following JIRA ticket for details:

As a result of this cleanup some minor code changes may be required to use this release.

Issues Resolved

See the PyMongo 2.2 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 2.1.1

Version 2.1.1 is a minor release that fixes a few issues discovered after the release of 2.1. You can now use ReplicaSetConnection to run inline map reduce commands on secondaries. See inline_map_reduce() for details.

Special thanks go to Samuel Clay and Ross Lawley for their contributions to this release.

Issues Resolved

See the PyMongo 2.1.1 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 2.1

Version 2.1 adds a few frequently requested features and includes the usual round of bug fixes and improvements.

Special thanks go to Alexey Borzenkov, Dan Crosta, Kostya Rybnikov, Flavio Percoco Premoli, Jonas Haag, and Jesse Davis for their contributions to this release.

Important New Features:

  • ReplicaSetConnection - ReplicaSetConnection can be used to distribute reads to secondaries in a replica set. It supports automatic failover handling and periodically checks the state of the replica set to handle issues like primary stepdown or secondaries being removed for backup operations. Read preferences are defined through ReadPreference.
  • PyMongo supports the new BSON binary subtype 4 for UUIDs. The default subtype to use can be set through uuid_subtype The current default remains OLD_UUID_SUBTYPE but will be changed to UUID_SUBTYPE in a future release.
  • The getLastError option ‘w’ can be set to a string, allowing for options like “majority” available in newer version of MongoDB.
  • Added support for the MongoDB URI options socketTimeoutMS and connectTimeoutMS.
  • Added support for the ContinueOnError insert flag.
  • Added basic SSL support.
  • Added basic support for Jython.
  • Secondaries can be used for count(), distinct(), group(), and querying GridFS.
  • Added document_class and tz_aware options to MasterSlaveConnection

Issues Resolved

See the PyMongo 2.1 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 2.0.1

Version 2.0.1 fixes a regression in GridIn when writing pre-chunked strings. Thanks go to Alexey Borzenkov for reporting the issue and submitting a patch.

Issues Resolved

  • PYTHON-271: Regression in GridFS leads to serious loss of data.

Changes in Version 2.0

Version 2.0 adds a large number of features and fixes a number of issues.

Special thanks go to James Murty, Abhay Vardhan, David Pisoni, Ryan Smith-Roberts, Andrew Pendleton, Mher Movsisyan, Reed O’Brien, Michael Schurter, Josip Delic and Jonas Haag for their contributions to this release.

Important New Features:

  • PyMongo now performs automatic per-socket database authentication. You no longer have to re-authenticate for each new thread or after a replica set failover. Authentication credentials are cached by the driver until the application calls logout().
  • slave_okay can be set independently at the connection, database, collection or query level. Each level will inherit the slave_okay setting from the previous level and each level can override the previous level’s setting.
  • safe and getLastError options (e.g. w, wtimeout, etc.) can be set independently at the connection, database, collection or query level. Each level will inherit settings from the previous level and each level can override the previous level’s setting.
  • PyMongo now supports the await_data and partial cursor flags. If the await_data flag is set on a tailable cursor the server will block for some extra time waiting for more data to return. The partial flag tells a mongos to return partial data for a query if not all shards are available.
  • map_reduce() will accept a dict or instance of SON as the out parameter.
  • The URI parser has been moved into its own module and can be used directly by application code.
  • AutoReconnect exception now provides information about the error that actually occured instead of a generic failure message.
  • A number of new helper methods have been added with options for setting and unsetting cursor flags, re-indexing a collection, fsync and locking a server, and getting the server’s current operations.

API changes:

  • If only one host:port pair is specified Connection will make a direct connection to only that host. Please note that slave_okay must be True in order to query from a secondary.
  • If more than one host:port pair is specified or the replicaset option is used PyMongo will treat the specified host:port pair(s) as a seed list and connect using replica set behavior.


The default subtype for Binary has changed from OLD_BINARY_SUBTYPE (2) to BINARY_SUBTYPE (0).

Issues Resolved

See the PyMongo 2.0 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 1.11

Version 1.11 adds a few new features and fixes a few more bugs.

New Features:

  • Basic IPv6 support: pymongo prefers IPv4 but will try IPv6. You can also specify an IPv6 address literal in the host parameter or a MongoDB URI provided it is enclosed in ‘[‘ and ‘]’.
  • max_pool_size option: previously pymongo had a hard coded pool size of 10 connections. With this change you can specify a different pool size as a parameter to Connection (max_pool_size=<integer>) or in the MongoDB URI (maxPoolSize=<integer>).
  • Find by metadata in GridFS: You can know specify query fields as keyword parameters for get_version() and get_last_version().
  • Per-query slave_okay option: slave_okay=True is now a valid keyword argument for find() and find_one().

API changes:

  • validate_collection() now returns a dict instead of a string. This change was required to deal with an API change on the server. This method also now takes the optional scandata and full parameters. See the documentation for more details.


The pool_size, auto_start_request, and timeout parameters for Connection have been completely removed in this release. They were deprecated in pymongo-1.4 and have had no effect since then. Please make sure that your code doesn’t currently pass these parameters when creating a Connection instance.

Issues resolved

  • PYTHON-241: Support setting slaveok at the cursor level.
  • PYTHON-240: Queries can sometimes permanently fail after a replica set fail over.
  • PYTHON-238: error after few million requests
  • PYTHON-237: Basic IPv6 support.
  • PYTHON-236: Restore option to specify pool size in Connection.
  • PYTHON-212: pymongo does not recover after stale config
  • PYTHON-138: Find method for GridFS

Changes in Version 1.10.1

Version 1.10.1 is primarily a bugfix release. It fixes a regression in version 1.10 that broke pickling of ObjectIds. A number of other bugs have been fixed as well.

There are two behavior changes to be aware of:

  • If a read slave raises AutoReconnect MasterSlaveConnection will now retry the query on each slave until it is successful or all slaves have raised AutoReconnect. Any other exception will immediately be raised. The order that the slaves are tried is random. Previously the read would be sent to one randomly chosen slave and AutoReconnect was immediately raised in case of a connection failure.
  • A Python long is now always BSON encoded as an int64. Previously the encoding was based only on the value of the field and a long with a value less than 2147483648 or greater than -2147483649 would always be BSON encoded as an int32.

Issues resolved

  • PYTHON-234: Fix to raise exception if any when building extensions
  • PYTHON-233: Add information to build and test with extensions on windows
  • PYTHON-232: Traceback when hashing a DBRef instance
  • PYTHON-231: Traceback when pickling a DBRef instance
  • PYTHON-230: Pickled ObjectIds are not compatible between pymongo 1.9 and 1.10
  • PYTHON-228: Cannot pickle bson.ObjectId
  • PYTHON-227: Traceback when calling find() on system.js
  • PYTHON-216: MasterSlaveConnection is missing disconnect() method
  • PYTHON-186: When storing integers, type is selected according to value instead of type
  • PYTHON-173: as_class option is not propogated by Cursor.clone
  • PYTHON-113: Redunducy in MasterSlaveConnection

Changes in Version 1.10

Version 1.10 includes changes to support new features in MongoDB 1.8.x. Highlights include a modified map/reduce API including an inline map/reduce helper method, a new find_and_modify helper, and the ability to query the server for the maximum BSON document size it supports.


MongoDB versions greater than 1.7.4 no longer generate temporary collections for map/reduce results. An output collection name must be provided and the output will replace any existing output collection with the same name. map_reduce() now requires the out parameter.

Issues resolved

  • PYTHON-225: ObjectId class definition should use __slots__.
  • PYTHON-223: Documentation fix.
  • PYTHON-220: Documentation fix.
  • PYTHON-219: KeyError in find_and_modify()
  • PYTHON-213: Query server for maximum BSON document size.
  • PYTHON-208: Fix Connection __repr__.
  • PYTHON-207: Changes to Map/Reduce API.
  • PYTHON-205: Accept slaveOk in the URI to match the URI docs.
  • PYTHON-203: When slave_okay=True and we only specify one host don’t autodetect other set members.
  • PYTHON-194: Show size when whining about a document being too large.
  • PYTHON-184: Raise DuplicateKeyError for duplicate keys in capped collections.
  • PYTHON-178: Don’t segfault when trying to encode a recursive data structure.
  • PYTHON-177: Don’t segfault when decoding dicts with broken iterators.
  • PYTHON-172: Fix a typo.
  • PYTHON-170: Add find_and_modify().
  • PYTHON-169: Support deepcopy of DBRef.
  • PYTHON-167: Duplicate of PYTHON-166.
  • PYTHON-166: Fixes a concurrency issue.
  • PYTHON-158: Add code and err string to db assertion messages.

Changes in Version 1.9

Version 1.9 adds a new package to the PyMongo distribution, bson. bson contains all of the BSON encoding and decoding logic, and the BSON types that were formerly in the pymongo package. The following modules have been renamed:

In addition, the following exception classes have been renamed:

The above exceptions now inherit from bson.errors.BSONError rather than pymongo.errors.PyMongoError.


All of the renamed modules and exceptions above have aliases created with the old names, so these changes should not break existing code. The old names will eventually be deprecated and then removed, so users should begin migrating towards the new names now.


The change to the exception hierarchy mentioned above is possibly breaking. If your code is catching PyMongoError, then the exceptions raised by bson will not be caught, even though they would have been caught previously. Before upgrading, it is recommended that users check for any cases like this.

  • the C extension now shares buffer.c/h with the Ruby driver
  • bson no longer raises InvalidName, all occurrences have been replaced with InvalidDocument.
  • renamed bson._to_dicts() to decode_all().
  • renamed from_dict() to encode() and to_dict() to decode().
  • added batch_size().
  • allow updating (some) file metadata after a GridIn instance has been closed.
  • performance improvements for reading from GridFS.
  • special cased slice with the same start and stop to return an empty cursor.
  • allow writing unicode to GridFS if an encoding attribute has been specified for the file.
  • added gridfs.GridFS.get_version().
  • scope variables for Code can now be specified as keyword arguments.
  • added readline() to GridOut.
  • make a best effort to transparently auto-reconnect if a Connection has been idle for a while.
  • added list() to SystemJS.
  • added file_document argument to GridOut() to allow initializing from an existing file document.
  • raise TimeoutError even if the getLastError command was run manually and not through “safe” mode.
  • added uuid support to json_util.

Changes in Version 1.8.1

  • fixed a typo in the C extension that could cause safe-mode operations to report a failure (SystemError) even when none occurred.
  • added a __ne__() implementation to any class where we define __eq__().

Changes in Version 1.8

Version 1.8 adds support for connecting to replica sets, specifying per-operation values for w and wtimeout, and decoding to timezone-aware datetimes.

  • fixed a reference leak in the C extension when decoding a DBRef.
  • added support for w, wtimeout, and fsync (and any other options for getLastError) to “safe mode” operations.
  • added nodes property.
  • added a maximum pool size of 10 sockets.
  • added support for replica sets.
  • DEPRECATED from_uri() and paired(), both are supplanted by extended functionality in Connection().
  • added tz aware support for datetimes in ObjectId, Timestamp and json_util methods.
  • added drop() helper.
  • reuse the socket used for finding the master when a Connection is first created.
  • added support for MinKey, MaxKey and Timestamp to json_util.
  • added support for decoding datetimes as aware (UTC) - it is highly recommended to enable this by setting the tz_aware parameter to Connection() to True.
  • added network_timeout option for individual calls to find() and find_one().
  • added exists() to check if a file exists in GridFS.
  • added support for additional keys in DBRef instances.
  • added code attribute to OperationFailure exceptions.
  • fixed serialization of int and float subclasses in the C extension.

Changes in Version 1.7

Version 1.7 is a recommended upgrade for all PyMongo users. The full release notes are below, and some more in depth discussion of the highlights is here.

  • no longer attempt to build the C extension on big-endian systems.
  • added MinKey and MaxKey.
  • use unsigned for Timestamp in BSON encoder/decoder.
  • support True as "ok" in command responses, in addition to 1.0 - necessary for server versions >= 1.5.X
  • BREAKING change to index_information() to add support for querying unique status and other index information.
  • added document_class, to specify class for returned documents.
  • added as_class argument for find(), and in the BSON decoder.
  • added support for creating Timestamp instances using a datetime.
  • allow dropTarget argument for rename.
  • handle aware datetime instances, by converting to UTC.
  • added support for max_scan.
  • raise FileExists exception when creating a duplicate GridFS file.
  • use y2038 for time handling in the C extension - eliminates 2038 problems when extension is installed.
  • added sort parameter to find()
  • finalized deprecation of changes from versions <= 1.4
  • take any non-dict as an "_id" query for find_one() or remove()
  • added ability to pass a dict for fields argument to find() (supports "$slice" and field negation)
  • simplified code to find master, since paired setups don’t always have a remote
  • fixed bug in C encoder for certain invalid types (like Collection instances).
  • don’t transparently map "filename" key to name attribute for GridFS.

Changes in Version 1.6

The biggest change in version 1.6 is a complete re-implementation of gridfs with a lot of improvements over the old implementation. There are many details and examples of using the new API in this blog post. The old API has been removed in this version, so existing code will need to be modified before upgrading to 1.6.

  • fixed issue where connection pool was being shared across Connection instances.
  • more improvements to Python code caching in C extension - should improve behavior on mod_wsgi.
  • added from_datetime().
  • complete rewrite of gridfs support.
  • improvements to the command() API.
  • fixed drop_indexes() behavior on non-existent collections.
  • disallow empty bulk inserts.

Changes in Version 1.5.2

  • fixed response handling to ignore unknown response flags in queries.
  • handle server versions containing ‘-pre-‘.

Changes in Version 1.5.1

  • added _id property for GridFile instances.
  • fix for making a Connection (with slave_okay set) directly to a slave in a replica pair.
  • accept kwargs for create_index() and ensure_index() to support all indexing options.
  • add pymongo.GEO2D and support for geo indexing.
  • improvements to Python code caching in C extension - should improve behavior on mod_wsgi.

Changes in Version 1.5

  • added subtype constants to binary module.
  • DEPRECATED options argument to Collection() and create_collection() in favor of kwargs.
  • added has_c() to check for C extension.
  • added copy_database().
  • added alive to tell when a cursor might have more data to return (useful for tailable cursors).
  • added Timestamp to better support dealing with internal MongoDB timestamps.
  • added name argument for create_index() and ensure_index().
  • fixed connection pooling w/ fork
  • paired() takes all kwargs that are allowed for Connection().
  • insert() returns list for bulk inserts of size one.
  • fixed handling of datetime.datetime instances in json_util.
  • added from_uri() to support MongoDB connection uri scheme.
  • fixed chunk number calculation when unaligned in gridfs.
  • command() takes a string for simple commands.
  • added system_js helper for dealing with server-side JS.
  • don’t wrap queries containing "$query" (support manual use of "$min", etc.).
  • added GridFSError as base class for gridfs exceptions.

Changes in Version 1.4

Perhaps the most important change in version 1.4 is that we have decided to no longer support Python 2.3. The most immediate reason for this is to allow some improvements to connection pooling. This will also allow us to use some new (as in Python 2.4 ;) idioms and will help begin the path towards supporting Python 3.0. If you need to use Python 2.3 you should consider using version 1.3 of this driver, although that will no longer be actively supported.

Other changes:

  • move "_id" to front only for top-level documents (fixes some corner cases).
  • update() and remove() return the entire response to the lastError command when safe is True.
  • completed removal of things that were deprecated in version 1.2 or earlier.
  • enforce that collection names do not contain the NULL byte.
  • fix to allow using UTF-8 collection names with the C extension.
  • added PyMongoError as base exception class for all errors. this changes the exception hierarchy somewhat, and is a BREAKING change if you depend on ConnectionFailure being a IOError or InvalidBSON being a ValueError, for example.
  • added DuplicateKeyError for calls to insert() or update() with safe set to True.
  • removed thread_util.
  • added add_user() and remove_user() helpers.
  • fix for authenticate() when using non-UTF-8 names or passwords.
  • minor fixes for MasterSlaveConnection.
  • clean up all cases where ConnectionFailure is raised.
  • simplification of connection pooling - makes driver ~2x faster for simple benchmarks. see How does connection pooling work in PyMongo? for more information.
  • DEPRECATED pool_size, auto_start_request and timeout parameters to Connection. DEPRECATED start_request().
  • use socket.sendall().
  • removed from_xml() as it was only being used for some internal testing - also eliminates dependency on elementtree.
  • implementation of update() in C.
  • deprecate _command() in favor of command().
  • send all commands without wrapping as {"query": ...}.
  • support string as key argument to group() (keyf) and run all groups as commands.
  • support for equality testing for Code instances.
  • allow the NULL byte in strings and disallow it in key names or regex patterns

Changes in Version 1.3

Changes in Version 1.2.1

  • added Changelog to docs
  • added doc --test to run doctests for tutorial, examples
  • moved most examples to Sphinx docs (and remove from examples/ directory)
  • raise InvalidId instead of TypeError when passing a 24 character string to ObjectId that contains non-hexadecimal characters
  • allow unicode instances for ObjectId init

Changes in Version 1.2

  • spec parameter for remove() is now optional to allow for deleting all documents in a Collection
  • always wrap queries with {query: ...} even when no special options - get around some issues with queries on fields named query
  • enforce 4MB document limit on the client side
  • added map_reduce() helper - see example
  • added distinct() method on Cursor instances to allow distinct with queries
  • fix for __getitem__() after skip()
  • allow any UTF-8 string in BSON encoder, not just ASCII subset
  • added generation_time
  • removed support for legacy ObjectId format - pretty sure this was never used, and is just confusing
  • DEPRECATED url_encode() and url_decode() in favor of str() and ObjectId(), respectively
  • allow oplog.$main as a valid collection name
  • some minor fixes for installation process
  • added support for datetime and regex in json_util

Changes in Version 1.1.2

  • improvements to insert() speed (using C for insert message creation)
  • use random number for request_id
  • fix some race conditions with AutoReconnect

Changes in Version 1.1.1

  • added multi parameter for update()
  • fix unicode regex patterns with C extension
  • added distinct()
  • added database support for DBRef
  • added json_util with helpers for encoding / decoding special types to JSON
  • DEPRECATED pymongo.cursor.Cursor.__len__() in favor of count() with with_limit_and_skip set to True due to performance regression
  • switch documentation to Sphinx

Changes in Version 1.1

  • added __hash__() for DBRef and ObjectId
  • bulk insert() works with any iterable
  • fix ObjectId generation when using multiprocessing
  • added collection
  • added network_timeout parameter for Connection()
  • DEPRECATED slave_okay parameter for individual queries
  • fix for safe mode when multi-threaded
  • added safe parameter for remove()
  • added tailable parameter for find()

Changes in Version 1.0

Changes in Version 0.16

  • support for encoding/decoding uuid.UUID instances
  • fix for explain() with limits

Changes in Version 0.15.2

  • documentation changes only

Changes in Version 0.15.1

  • various performance improvements
  • API CHANGE no longer need to specify direction for create_index() and ensure_index() when indexing a single key
  • support for encoding tuple instances as list instances

Changes in Version 0.15

  • fix string representation of ObjectId instances
  • added timeout parameter for find()
  • allow scope for reduce function in group()

Changes in Version 0.14.2

  • minor bugfixes

Changes in Version 0.14.1

  • seek() and tell() for (read mode) GridFile instances

Changes in Version 0.14

Changes in Version 0.13

Changes in Version 0.12

Changes in Version 0.11.3

  • don’t allow NULL bytes in string encoder
  • fixes for Python 2.3

Changes in Version 0.11.2

  • PEP 8
  • updates for group()
  • VS build

Changes in Version 0.11.1

  • fix for connection pooling under Python 2.5

Changes in Version 0.11

  • better build failure detection
  • driver support for selecting fields in sub-documents
  • disallow insertion of invalid key names
  • added timeout parameter for Connection()

Changes in Version 0.10.3

  • fix bug with large limit()
  • better exception when modules get reloaded out from underneath the C extension
  • better exception messages when calling a Collection or Database instance

Changes in Version 0.10.2

  • support subclasses of dict in C encoder

Changes in Version 0.10.1

Changes in Version 0.10

Changes in Version 0.9.7

  • allow sub-collections of $cmd as valid Collection names
  • add version as pymongo.version
  • add --no_ext command line option to