Interface IMongoClient
The client interface to MongoDB.
public interface IMongoClient
- Extension Methods
Remarks
This interface is not guaranteed to remain stable. Implementors should use MongoClientBase.
Properties
Cluster
Gets the cluster.
ICluster Cluster { get; }
Property Value
- ICluster
The cluster.
Settings
Gets the settings.
MongoClientSettings Settings { get; }
Property Value
Methods
DropDatabase(IClientSessionHandle, string, CancellationToken)
Drops the database with the specified name.
void DropDatabase(IClientSessionHandle session, string name, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
name
stringThe name of the database to drop.
cancellationToken
CancellationTokenThe cancellation token.
DropDatabase(string, CancellationToken)
Drops the database with the specified name.
void DropDatabase(string name, CancellationToken cancellationToken = default)
Parameters
name
stringThe name of the database to drop.
cancellationToken
CancellationTokenThe cancellation token.
DropDatabaseAsync(IClientSessionHandle, string, CancellationToken)
Drops the database with the specified name.
Task DropDatabaseAsync(IClientSessionHandle session, string name, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
name
stringThe name of the database to drop.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task
A task.
DropDatabaseAsync(string, CancellationToken)
Drops the database with the specified name.
Task DropDatabaseAsync(string name, CancellationToken cancellationToken = default)
Parameters
name
stringThe name of the database to drop.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task
A task.
GetDatabase(string, MongoDatabaseSettings)
Gets a database.
IMongoDatabase GetDatabase(string name, MongoDatabaseSettings settings = null)
Parameters
name
stringThe name of the database.
settings
MongoDatabaseSettingsThe database settings.
Returns
- IMongoDatabase
An implementation of a database.
ListDatabaseNames(IClientSessionHandle, ListDatabaseNamesOptions, CancellationToken)
Returns the names of the databases on the server.
IAsyncCursor<string> ListDatabaseNames(IClientSessionHandle session, ListDatabaseNamesOptions options, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
options
ListDatabaseNamesOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- IAsyncCursor<string>
The database names.
ListDatabaseNames(IClientSessionHandle, CancellationToken)
Returns the names of the databases on the server.
IAsyncCursor<string> ListDatabaseNames(IClientSessionHandle session, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- IAsyncCursor<string>
The database names.
ListDatabaseNames(ListDatabaseNamesOptions, CancellationToken)
Returns the names of the databases on the server.
IAsyncCursor<string> ListDatabaseNames(ListDatabaseNamesOptions options, CancellationToken cancellationToken = default)
Parameters
options
ListDatabaseNamesOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- IAsyncCursor<string>
The database names.
ListDatabaseNames(CancellationToken)
Returns the names of the databases on the server.
IAsyncCursor<string> ListDatabaseNames(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationTokenThe cancellation token.
Returns
- IAsyncCursor<string>
The database names.
ListDatabaseNamesAsync(IClientSessionHandle, ListDatabaseNamesOptions, CancellationToken)
Returns the names of the databases on the server.
Task<IAsyncCursor<string>> ListDatabaseNamesAsync(IClientSessionHandle session, ListDatabaseNamesOptions options, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
options
ListDatabaseNamesOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<IAsyncCursor<string>>
The database names.
ListDatabaseNamesAsync(IClientSessionHandle, CancellationToken)
Returns the names of the databases on the server.
Task<IAsyncCursor<string>> ListDatabaseNamesAsync(IClientSessionHandle session, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<IAsyncCursor<string>>
The database names.
ListDatabaseNamesAsync(ListDatabaseNamesOptions, CancellationToken)
Returns the names of the databases on the server.
Task<IAsyncCursor<string>> ListDatabaseNamesAsync(ListDatabaseNamesOptions options, CancellationToken cancellationToken = default)
Parameters
options
ListDatabaseNamesOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<IAsyncCursor<string>>
The database names.
ListDatabaseNamesAsync(CancellationToken)
Returns the names of the databases on the server.
Task<IAsyncCursor<string>> ListDatabaseNamesAsync(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<IAsyncCursor<string>>
The database names.
ListDatabases(IClientSessionHandle, ListDatabasesOptions, CancellationToken)
Lists the databases on the server.
IAsyncCursor<BsonDocument> ListDatabases(IClientSessionHandle session, ListDatabasesOptions options, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
options
ListDatabasesOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- IAsyncCursor<BsonDocument>
A cursor.
ListDatabases(IClientSessionHandle, CancellationToken)
Lists the databases on the server.
IAsyncCursor<BsonDocument> ListDatabases(IClientSessionHandle session, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- IAsyncCursor<BsonDocument>
A cursor.
ListDatabases(ListDatabasesOptions, CancellationToken)
Lists the databases on the server.
IAsyncCursor<BsonDocument> ListDatabases(ListDatabasesOptions options, CancellationToken cancellationToken = default)
Parameters
options
ListDatabasesOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- IAsyncCursor<BsonDocument>
A cursor.
ListDatabases(CancellationToken)
Lists the databases on the server.
IAsyncCursor<BsonDocument> ListDatabases(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationTokenThe cancellation token.
Returns
- IAsyncCursor<BsonDocument>
A cursor.
ListDatabasesAsync(IClientSessionHandle, ListDatabasesOptions, CancellationToken)
Lists the databases on the server.
Task<IAsyncCursor<BsonDocument>> ListDatabasesAsync(IClientSessionHandle session, ListDatabasesOptions options, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
options
ListDatabasesOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<IAsyncCursor<BsonDocument>>
A Task whose result is a cursor.
ListDatabasesAsync(IClientSessionHandle, CancellationToken)
Lists the databases on the server.
Task<IAsyncCursor<BsonDocument>> ListDatabasesAsync(IClientSessionHandle session, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<IAsyncCursor<BsonDocument>>
A Task whose result is a cursor.
ListDatabasesAsync(ListDatabasesOptions, CancellationToken)
Lists the databases on the server.
Task<IAsyncCursor<BsonDocument>> ListDatabasesAsync(ListDatabasesOptions options, CancellationToken cancellationToken = default)
Parameters
options
ListDatabasesOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<IAsyncCursor<BsonDocument>>
A Task whose result is a cursor.
ListDatabasesAsync(CancellationToken)
Lists the databases on the server.
Task<IAsyncCursor<BsonDocument>> ListDatabasesAsync(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<IAsyncCursor<BsonDocument>>
A Task whose result is a cursor.
StartSession(ClientSessionOptions, CancellationToken)
Starts a client session.
IClientSessionHandle StartSession(ClientSessionOptions options = null, CancellationToken cancellationToken = default)
Parameters
options
ClientSessionOptionsThe session options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- IClientSessionHandle
A client session.
StartSessionAsync(ClientSessionOptions, CancellationToken)
Starts a client session.
Task<IClientSessionHandle> StartSessionAsync(ClientSessionOptions options = null, CancellationToken cancellationToken = default)
Parameters
options
ClientSessionOptionsThe session options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<IClientSessionHandle>
A Task whose result is a client session.
WatchAsync<TResult>(IClientSessionHandle, PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult>, ChangeStreamOptions, CancellationToken)
Watches changes on all collections in all databases.
Task<IChangeStreamCursor<TResult>> WatchAsync<TResult>(IClientSessionHandle session, PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
pipeline
PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult>The pipeline.
options
ChangeStreamOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<IChangeStreamCursor<TResult>>
A change stream.
Type Parameters
TResult
The type of the result.
WatchAsync<TResult>(PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult>, ChangeStreamOptions, CancellationToken)
Watches changes on all collections in all databases.
Task<IChangeStreamCursor<TResult>> WatchAsync<TResult>(PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default)
Parameters
pipeline
PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult>The pipeline.
options
ChangeStreamOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<IChangeStreamCursor<TResult>>
A change stream.
Type Parameters
TResult
The type of the result.
Watch<TResult>(IClientSessionHandle, PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult>, ChangeStreamOptions, CancellationToken)
Watches changes on all collections in all databases.
IChangeStreamCursor<TResult> Watch<TResult>(IClientSessionHandle session, PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
pipeline
PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult>The pipeline.
options
ChangeStreamOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- IChangeStreamCursor<TResult>
A change stream.
Type Parameters
TResult
The type of the result.
Watch<TResult>(PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult>, ChangeStreamOptions, CancellationToken)
Watches changes on all collections in all databases.
IChangeStreamCursor<TResult> Watch<TResult>(PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default)
Parameters
pipeline
PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult>The pipeline.
options
ChangeStreamOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- IChangeStreamCursor<TResult>
A change stream.
Type Parameters
TResult
The type of the result.
WithReadConcern(ReadConcern)
Returns a new IMongoClient instance with a different read concern setting.
IMongoClient WithReadConcern(ReadConcern readConcern)
Parameters
readConcern
ReadConcernThe read concern.
Returns
- IMongoClient
A new IMongoClient instance with a different read concern setting.
WithReadPreference(ReadPreference)
Returns a new IMongoClient instance with a different read preference setting.
IMongoClient WithReadPreference(ReadPreference readPreference)
Parameters
readPreference
ReadPreferenceThe read preference.
Returns
- IMongoClient
A new IMongoClient instance with a different read preference setting.
WithWriteConcern(WriteConcern)
Returns a new IMongoClient instance with a different write concern setting.
IMongoClient WithWriteConcern(WriteConcern writeConcern)
Parameters
writeConcern
WriteConcernThe write concern.
Returns
- IMongoClient
A new IMongoClient instance with a different write concern setting.