| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432 |
- /* Copyright 2010-present MongoDB Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- using System;
- using System.Collections.Generic;
- using System.Threading;
- using System.Threading.Tasks;
- using MongoDB.Bson;
- namespace MongoDB.Driver
- {
- /// <summary>
- /// Represents a database in MongoDB.
- /// </summary>
- /// <remarks>
- /// This interface is not guaranteed to remain stable. Implementors should use
- /// <see cref="MongoDatabaseBase" />.
- /// </remarks>
- public interface IMongoDatabase
- {
- /// <summary>
- /// Gets the client.
- /// </summary>
- IMongoClient Client { get; }
- /// <summary>
- /// Gets the namespace of the database.
- /// </summary>
- DatabaseNamespace DatabaseNamespace { get; }
- /// <summary>
- /// Gets the settings.
- /// </summary>
- MongoDatabaseSettings Settings { get; }
- /// <summary>
- /// Creates the collection with the specified name.
- /// </summary>
- /// <param name="name">The name.</param>
- /// <param name="options">The options.</param>
- /// <param name="cancellationToken">The cancellation token.</param>
- void CreateCollection(string name, CreateCollectionOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
- /// <summary>
- /// Creates the collection with the specified name.
- /// </summary>
- /// <param name="session">The session.</param>
- /// <param name="name">The name.</param>
- /// <param name="options">The options.</param>
- /// <param name="cancellationToken">The cancellation token.</param>
- void CreateCollection(IClientSessionHandle session, string name, CreateCollectionOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
- /// <summary>
- /// Creates the collection with the specified name.
- /// </summary>
- /// <param name="name">The name.</param>
- /// <param name="options">The options.</param>
- /// <param name="cancellationToken">The cancellation token.</param>
- /// <returns>A task.</returns>
- Task CreateCollectionAsync(string name, CreateCollectionOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
- /// <summary>
- /// Creates the collection with the specified name.
- /// </summary>
- /// <param name="session">The session.</param>
- /// <param name="name">The name.</param>
- /// <param name="options">The options.</param>
- /// <param name="cancellationToken">The cancellation token.</param>
- /// <returns>
- /// A task.
- /// </returns>
- Task CreateCollectionAsync(IClientSessionHandle session, string name, CreateCollectionOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
- /// <summary>
- /// Creates a view.
- /// </summary>
- /// <typeparam name="TDocument">The type of the input documents.</typeparam>
- /// <typeparam name="TResult">The type of the pipeline result documents.</typeparam>
- /// <param name="viewName">The name of the view.</param>
- /// <param name="viewOn">The name of the collection that the view is on.</param>
- /// <param name="pipeline">The pipeline.</param>
- /// <param name="options">The options.</param>
- /// <param name="cancellationToken">The cancellation token.</param>
- void CreateView<TDocument, TResult>(string viewName, string viewOn, PipelineDefinition<TDocument, TResult> pipeline, CreateViewOptions<TDocument> options = null, CancellationToken cancellationToken = default(CancellationToken));
- /// <summary>
- /// Creates a view.
- /// </summary>
- /// <typeparam name="TDocument">The type of the input documents.</typeparam>
- /// <typeparam name="TResult">The type of the pipeline result documents.</typeparam>
- /// <param name="session">The session.</param>
- /// <param name="viewName">The name of the view.</param>
- /// <param name="viewOn">The name of the collection that the view is on.</param>
- /// <param name="pipeline">The pipeline.</param>
- /// <param name="options">The options.</param>
- /// <param name="cancellationToken">The cancellation token.</param>
- void CreateView<TDocument, TResult>(IClientSessionHandle session, string viewName, string viewOn, PipelineDefinition<TDocument, TResult> pipeline, CreateViewOptions<TDocument> options = null, CancellationToken cancellationToken = default(CancellationToken));
- /// <summary>
- /// Creates a view.
- /// </summary>
- /// <typeparam name="TDocument">The type of the input documents.</typeparam>
- /// <typeparam name="TResult">The type of the pipeline result documents.</typeparam>
- /// <param name="viewName">The name of the view.</param>
- /// <param name="viewOn">The name of the collection that the view is on.</param>
- /// <param name="pipeline">The pipeline.</param>
- /// <param name="options">The options.</param>
- /// <param name="cancellationToken">The cancellation token.</param>
- /// <returns>A task.</returns>
- Task CreateViewAsync<TDocument, TResult>(string viewName, string viewOn, PipelineDefinition<TDocument, TResult> pipeline, CreateViewOptions<TDocument> options = null, CancellationToken cancellationToken = default(CancellationToken));
- /// <summary>
- /// Creates a view.
- /// </summary>
- /// <typeparam name="TDocument">The type of the input documents.</typeparam>
- /// <typeparam name="TResult">The type of the pipeline result documents.</typeparam>
- /// <param name="session">The session.</param>
- /// <param name="viewName">The name of the view.</param>
- /// <param name="viewOn">The name of the collection that the view is on.</param>
- /// <param name="pipeline">The pipeline.</param>
- /// <param name="options">The options.</param>
- /// <param name="cancellationToken">The cancellation token.</param>
- /// <returns>
- /// A task.
- /// </returns>
- Task CreateViewAsync<TDocument, TResult>(IClientSessionHandle session, string viewName, string viewOn, PipelineDefinition<TDocument, TResult> pipeline, CreateViewOptions<TDocument> options = null, CancellationToken cancellationToken = default(CancellationToken));
- /// <summary>
- /// Drops the collection with the specified name.
- /// </summary>
- /// <param name="name">The name of the collection to drop.</param>
- /// <param name="cancellationToken">The cancellation token.</param>
- void DropCollection(string name, CancellationToken cancellationToken = default(CancellationToken));
- /// <summary>
- /// Drops the collection with the specified name.
- /// </summary>
- /// <param name="session">The session.</param>
- /// <param name="name">The name of the collection to drop.</param>
- /// <param name="cancellationToken">The cancellation token.</param>
- void DropCollection(IClientSessionHandle session, string name, CancellationToken cancellationToken = default(CancellationToken));
- /// <summary>
- /// Drops the collection with the specified name.
- /// </summary>
- /// <param name="name">The name of the collection to drop.</param>
- /// <param name="cancellationToken">The cancellation token.</param>
- /// <returns>A task.</returns>
- Task DropCollectionAsync(string name, CancellationToken cancellationToken = default(CancellationToken));
- /// <summary>
- /// Drops the collection with the specified name.
- /// </summary>
- /// <param name="session">The session.</param>
- /// <param name="name">The name of the collection to drop.</param>
- /// <param name="cancellationToken">The cancellation token.</param>
- /// <returns>
- /// A task.
- /// </returns>
- Task DropCollectionAsync(IClientSessionHandle session, string name, CancellationToken cancellationToken = default(CancellationToken));
- /// <summary>
- /// Gets a collection.
- /// </summary>
- /// <typeparam name="TDocument">The document type.</typeparam>
- /// <param name="name">The name of the collection.</param>
- /// <param name="settings">The settings.</param>
- /// <returns>An implementation of a collection.</returns>
- IMongoCollection<TDocument> GetCollection<TDocument>(string name, MongoCollectionSettings settings = null);
- /// <summary>
- /// Lists the names of all the collections in the database.
- /// </summary>
- /// <param name="options">The options.</param>
- /// <param name="cancellationToken">The cancellation token.</param>
- /// <returns>A cursor.</returns>
- IAsyncCursor<string> ListCollectionNames(ListCollectionNamesOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
- /// <summary>
- /// Lists the names of all the collections in the database.
- /// </summary>
- /// <param name="session">The session.</param>
- /// <param name="options">The options.</param>
- /// <param name="cancellationToken">The cancellation token.</param>
- /// <returns>A cursor.</returns>
- IAsyncCursor<string> ListCollectionNames(IClientSessionHandle session, ListCollectionNamesOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
- /// <summary>
- /// Lists the names of all the collections in the database.
- /// </summary>
- /// <param name="options">The options.</param>
- /// <param name="cancellationToken">The cancellation token.</param>
- /// <returns>A Task whose result is a cursor.</returns>
- Task<IAsyncCursor<string>> ListCollectionNamesAsync(ListCollectionNamesOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
- /// <summary>
- /// Lists the names of all the collections in the database.
- /// </summary>
- /// <param name="session">The session.</param>
- /// <param name="options">The options.</param>
- /// <param name="cancellationToken">The cancellation token.</param>
- /// <returns>A Task whose result is a cursor.</returns>
- Task<IAsyncCursor<string>> ListCollectionNamesAsync(IClientSessionHandle session, ListCollectionNamesOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
- /// <summary>
- /// Lists all the collections in the database.
- /// </summary>
- /// <param name="options">The options.</param>
- /// <param name="cancellationToken">The cancellation token.</param>
- /// <returns>A cursor.</returns>
- IAsyncCursor<BsonDocument> ListCollections(ListCollectionsOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
- /// <summary>
- /// Lists all the collections in the database.
- /// </summary>
- /// <param name="session">The session.</param>
- /// <param name="options">The options.</param>
- /// <param name="cancellationToken">The cancellation token.</param>
- /// <returns>
- /// A cursor.
- /// </returns>
- IAsyncCursor<BsonDocument> ListCollections(IClientSessionHandle session, ListCollectionsOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
- /// <summary>
- /// Lists all the collections in the database.
- /// </summary>
- /// <param name="options">The options.</param>
- /// <param name="cancellationToken">The cancellation token.</param>
- /// <returns>A Task whose result is a cursor.</returns>
- Task<IAsyncCursor<BsonDocument>> ListCollectionsAsync(ListCollectionsOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
- /// <summary>
- /// Lists all the collections in the database.
- /// </summary>
- /// <param name="session">The session.</param>
- /// <param name="options">The options.</param>
- /// <param name="cancellationToken">The cancellation token.</param>
- /// <returns>
- /// A Task whose result is a cursor.
- /// </returns>
- Task<IAsyncCursor<BsonDocument>> ListCollectionsAsync(IClientSessionHandle session, ListCollectionsOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
- /// <summary>
- /// Renames the collection.
- /// </summary>
- /// <param name="oldName">The old name.</param>
- /// <param name="newName">The new name.</param>
- /// <param name="options">The options.</param>
- /// <param name="cancellationToken">The cancellation token.</param>
- void RenameCollection(string oldName, string newName, RenameCollectionOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
- /// <summary>
- /// Renames the collection.
- /// </summary>
- /// <param name="session">The session.</param>
- /// <param name="oldName">The old name.</param>
- /// <param name="newName">The new name.</param>
- /// <param name="options">The options.</param>
- /// <param name="cancellationToken">The cancellation token.</param>
- void RenameCollection(IClientSessionHandle session, string oldName, string newName, RenameCollectionOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
- /// <summary>
- /// Renames the collection.
- /// </summary>
- /// <param name="oldName">The old name.</param>
- /// <param name="newName">The new name.</param>
- /// <param name="options">The options.</param>
- /// <param name="cancellationToken">The cancellation token.</param>
- /// <returns>A task.</returns>
- Task RenameCollectionAsync(string oldName, string newName, RenameCollectionOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
- /// <summary>
- /// Renames the collection.
- /// </summary>
- /// <param name="session">The session.</param>
- /// <param name="oldName">The old name.</param>
- /// <param name="newName">The new name.</param>
- /// <param name="options">The options.</param>
- /// <param name="cancellationToken">The cancellation token.</param>
- /// <returns>
- /// A task.
- /// </returns>
- Task RenameCollectionAsync(IClientSessionHandle session, string oldName, string newName, RenameCollectionOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
- /// <summary>
- /// Runs a command.
- /// </summary>
- /// <typeparam name="TResult">The result type of the command.</typeparam>
- /// <param name="command">The command.</param>
- /// <param name="readPreference">The read preference.</param>
- /// <param name="cancellationToken">The cancellation token.</param>
- /// <returns>
- /// The result of the command.
- /// </returns>
- TResult RunCommand<TResult>(Command<TResult> command, ReadPreference readPreference = null, CancellationToken cancellationToken = default(CancellationToken));
- /// <summary>
- /// Runs a command.
- /// </summary>
- /// <typeparam name="TResult">The result type of the command.</typeparam>
- /// <param name="session">The session.</param>
- /// <param name="command">The command.</param>
- /// <param name="readPreference">The read preference.</param>
- /// <param name="cancellationToken">The cancellation token.</param>
- /// <returns>
- /// The result of the command.
- /// </returns>
- TResult RunCommand<TResult>(IClientSessionHandle session, Command<TResult> command, ReadPreference readPreference = null, CancellationToken cancellationToken = default(CancellationToken));
- /// <summary>
- /// Runs a command.
- /// </summary>
- /// <typeparam name="TResult">The result type of the command.</typeparam>
- /// <param name="command">The command.</param>
- /// <param name="readPreference">The read preference.</param>
- /// <param name="cancellationToken">The cancellation token.</param>
- /// <returns>
- /// The result of the command.
- /// </returns>
- Task<TResult> RunCommandAsync<TResult>(Command<TResult> command, ReadPreference readPreference = null, CancellationToken cancellationToken = default(CancellationToken));
- /// <summary>
- /// Runs a command.
- /// </summary>
- /// <typeparam name="TResult">The result type of the command.</typeparam>
- /// <param name="session">The session.</param>
- /// <param name="command">The command.</param>
- /// <param name="readPreference">The read preference.</param>
- /// <param name="cancellationToken">The cancellation token.</param>
- /// <returns>
- /// The result of the command.
- /// </returns>
- Task<TResult> RunCommandAsync<TResult>(IClientSessionHandle session, Command<TResult> command, ReadPreference readPreference = null, CancellationToken cancellationToken = default(CancellationToken));
- /// <summary>
- /// Watches changes on all collections in a database.
- /// </summary>
- /// <typeparam name="TResult">The type of the result.</typeparam>
- /// <param name="pipeline">The pipeline.</param>
- /// <param name="options">The options.</param>
- /// <param name="cancellationToken">The cancellation token.</param>
- /// <returns>
- /// A change stream.
- /// </returns>
- IAsyncCursor<TResult> Watch<TResult>(
- PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult> pipeline,
- ChangeStreamOptions options = null,
- CancellationToken cancellationToken = default(CancellationToken));
- /// <summary>
- /// Watches changes on all collections in a database.
- /// </summary>
- /// <typeparam name="TResult">The type of the result.</typeparam>
- /// <param name="session">The session.</param>
- /// <param name="pipeline">The pipeline.</param>
- /// <param name="options">The options.</param>
- /// <param name="cancellationToken">The cancellation token.</param>
- /// <returns>
- /// A change stream.
- /// </returns>
- IAsyncCursor<TResult> Watch<TResult>(
- IClientSessionHandle session,
- PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult> pipeline,
- ChangeStreamOptions options = null,
- CancellationToken cancellationToken = default(CancellationToken));
- /// <summary>
- /// Watches changes on all collections in a database.
- /// </summary>
- /// <typeparam name="TResult">The type of the result.</typeparam>
- /// <param name="pipeline">The pipeline.</param>
- /// <param name="options">The options.</param>
- /// <param name="cancellationToken">The cancellation token.</param>
- /// <returns>
- /// A change stream.
- /// </returns>
- Task<IAsyncCursor<TResult>> WatchAsync<TResult>(
- PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult> pipeline,
- ChangeStreamOptions options = null,
- CancellationToken cancellationToken = default(CancellationToken));
- /// <summary>
- /// Watches changes on all collections in a database.
- /// </summary>
- /// <typeparam name="TResult">The type of the result.</typeparam>
- /// <param name="session">The session.</param>
- /// <param name="pipeline">The pipeline.</param>
- /// <param name="options">The options.</param>
- /// <param name="cancellationToken">The cancellation token.</param>
- /// <returns>
- /// A change stream.
- /// </returns>
- Task<IAsyncCursor<TResult>> WatchAsync<TResult>(
- IClientSessionHandle session,
- PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult> pipeline,
- ChangeStreamOptions options = null,
- CancellationToken cancellationToken = default(CancellationToken));
- /// <summary>
- /// Returns a new IMongoDatabase instance with a different read concern setting.
- /// </summary>
- /// <param name="readConcern">The read concern.</param>
- /// <returns>A new IMongoDatabase instance with a different read concern setting.</returns>
- IMongoDatabase WithReadConcern(ReadConcern readConcern);
- /// <summary>
- /// Returns a new IMongoDatabase instance with a different read preference setting.
- /// </summary>
- /// <param name="readPreference">The read preference.</param>
- /// <returns>A new IMongoDatabase instance with a different read preference setting.</returns>
- IMongoDatabase WithReadPreference(ReadPreference readPreference);
- /// <summary>
- /// Returns a new IMongoDatabase instance with a different write concern setting.
- /// </summary>
- /// <param name="writeConcern">The write concern.</param>
- /// <returns>A new IMongoDatabase instance with a different write concern setting.</returns>
- IMongoDatabase WithWriteConcern(WriteConcern writeConcern);
- }
- }
|