This commit introduces the following changes:
- Each read preference is now a class.
- Read preferences other than Primary accept a tag_sets parameter.
- The tag_sets attribute of MongoClient, Database, and Collection has
been removed. Use the tag_sets parameter of the new classes instead.
- The read_preferences.ReadPreference constant still exists and should
continue to work as expected for most users.
- Renamed to acceptableLatencyMS since it is also used
in choosing a new mongos during mongos HA failover.
- Moved to a global immutable setting. The expectation is
that the value would be determined by a network/system
admin. Changing it per operation doesn't make a lot of
sense.
Note - it's possible the name of this option may change again
before 3.0 is released.
MongoDB master/slave clusters are deprecated. Use replica
sets instead. If you must use this client class the 2.x
branch of PyMongo will continue to be maintained for some
time.
This was always a misguided feature. Using a socket timeout
to "timeout" MongoDB queries is awful for a few reasons:
- It leaves the query running on the server, wasting resources.
- It causes a socket to be closed and discarded unnecessarily.
- Applications that use this tend to immediately retry the query,
often causing another timeout and more wasted resources.
There are three remaining ways to use timeouts with PyMongo:
- connectTimeoutMS - Global setting for timing out a socket's
initial connection to the server.
- socketTimeoutMS - Global setting for timing out any socket
operation. *Do not* use this to enforce time limits on server
side operations.
- max_time_ms (or maxTimeoutMS as a command kwarg) - MongoDB 2.6
server side timebomb for queries and commands. This is a server
side option, passed along with a query or command, that causes
MongoDB to abort the operation if it takes longer than the specified
limit.
This commit adds a helper for the new parallelCollectionScan
command introduced in MongoDB 2.5.5. The helper returns
"num_cursors" instances of CommandCursor that can be iterated
by one or more threads concurrently to scan the entire collection.
This commit also removes the remaining command cursor
hacks from cursor.Cursor.
The cursor returned by aggregate now knows what server
it was created on, allowing it to return getMore results
when the read preference is not PRIMARY.
This also introduces a simplified cursor class for use
with commands that return a cursor id and perhaps an initial
set of results. None of the methods of cursor.Cursor (other
than batch_size) make sense in this case.
Add a 'compile_re' parameter to Collection.find, Collection.find_one, and
json_util.loads. If it's False, regular expressions are encoded as a new class,
Regex, instead of passed to re.compile(). This allows PyMongo to handle regular
expressions that don't compile in Python but are valid in other contexts like
MongoDB queries.
This change adds two new top level classes, MongoClient
and MongoReplicaSetClient. They work almost exactly the
same as Connection and ReplicaSetConnection with a few
differences:
1. These connection objects awknowledge write operations by default.
2. The network_timeout parameter is gone, use socketTimeoutMS instead.
3. auto_start_request defaults to False.
Default acknowledged write operation will be the biggest change for
most users. Using MongoClient and MongoReplicaSetClient you no longer
have to pass safe=True to a write method (save, update, insert, remove)
to request an acknowledgement from the server.
Connection and ReplicaSetConnection are now deprecated but retain their
previous behavior. This should not be a backward breaking change.
This change deprecates get|set|unset_lasterror_options,
replacing them with a write_concern attribute that can be
accessed directly. See the write_concern docstring for
an example of its use.
Replace the 'mongo' dict with a Member object everywhere in ReplicaSetConnection.
A handful of commands obey read preferences; most are always sent to primary.
Track a 5-sample moving average of each replica set member's ping time.
Connection detects whether it's connected to primary, secondary, or mongos.