MongoRepository(T, TKey).RequestStart Method

MongoRepository

MongoRepositoryT, TKeyRequestStart Method
Lets the server know that this thread is about to begin a series of related operations that must all occur on the same connection. The return value of this method implements IDisposable and can be placed in a using statement (in which case RequestDone will be called automatically when leaving the using statement).

Namespace: MongoRepository
Assembly: MongoRepository.Net45 (in MongoRepository.Net45.dll) Version: 1.6.11.0 (1.6.11.0)
Syntax
public virtual IDisposable RequestStart()
Public Overridable Function RequestStart As IDisposable
public:
virtual IDisposable^ RequestStart()
abstract RequestStart : unit -> IDisposable 
override RequestStart : unit -> IDisposable 

Return Value

Type: IDisposable
A helper object that implements IDisposable and calls RequestDone() from the Dispose method.

Implements

IRepositoryT, TKeyRequestStart
Remarks

Sometimes a series of operations needs to be performed on the same connection in order to guarantee correct results. This is rarely the case, and most of the time there is no need to call RequestStart/RequestDone. An example of when this might be necessary is when a series of Inserts are called in rapid succession with SafeMode off, and you want to query that data in a consistent manner immediately thereafter (with SafeMode off the writes can queue up at the server and might not be immediately visible to other connections). Using RequestStart you can force a query to be on the same connection as the writes, so the query won't execute until the server has caught up with the writes.

A thread can temporarily reserve a connection from the connection pool by using RequestStart and RequestDone. You are free to use any other databases as well during the request. RequestStart increments a counter (for this thread) and RequestDone decrements the counter. The connection that was reserved is not actually returned to the connection pool until the count reaches zero again. This means that calls to RequestStart/RequestDone can be nested and the right thing will happen.

Use the connectionstring to specify the readpreference; add "readPreference=X" where X is one of the following values: primary, primaryPreferred, secondary, secondaryPreferred, nearest. See http://docs.mongodb.org/manual/applications/replication/#read-preference

See Also