Details
-
New Feature
-
Resolution: Done
-
Major - P3
-
None
-
1.7
-
None
-
None
Description
In 1.7 database and collection objects can be considered to be "bound" to a cluster, since operations can be performed against any member of the cluster (subject to any ReadPreference provided).
The only mechanism provided to "bind" a series of operations to a single connection is RequestStart/Done. But RequestStart/Done is problematic because it relies on thread affinity, which makes it very unfriendly to a future async implementation.
We are going to obsolete RequestStart/Done and replace it with a new concept we call "binding". In general terms, an IMongoBinding can be thought of as a source of bound objects, and a bound object is one that performs operations using a connection provided by the binding it is bound to.
The following classes are "bindings": MongoClient/MongoServer, MongoServerInstance and MongoConnection. They represent successively tighter bindings.
The following classes are "bound objects": MongoDatabase and MongoCollection.
Here is some sample code showing how to perform a series of operations using a single connection:
using (var connection = server.GetConnection())
|
{
|
var database = connection.GetDatabase("test"); // database is bound to the connection
|
var collection = database.GetCollection("test"); // and collection is also
|
// perform a series of operations
|
}
|
Note that the connection is used in a "using" statement, and will be released back to the connection pool when the using statement is left.
This will be backward breaking if you use RequestStart/Done. In version 1.8 we are only deprecating RequestStart/Done, but in a later version it will be removed.
Attachments
Issue Links
- is related to
-
CSHARP-203 Plugin load balancer for distributing reads to secondaries
-
- Closed
-