/* Copyright 2010-2016 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;
using MongoDB.Bson.Serialization;
namespace MongoDB.Driver
{
///
/// Represents a typed collection in MongoDB.
///
///
/// This interface is not guaranteed to remain stable. Implementors should use
/// .
///
/// The type of the documents stored in the collection.
public interface IMongoCollection
{
///
/// Gets the namespace of the collection.
///
CollectionNamespace CollectionNamespace { get; }
///
/// Gets the database.
///
IMongoDatabase Database { get; }
///
/// Gets the document serializer.
///
IBsonSerializer DocumentSerializer { get; }
///
/// Gets the index manager.
///
IMongoIndexManager Indexes { get; }
///
/// Gets the settings.
///
MongoCollectionSettings Settings { get; }
///
/// Runs an aggregation pipeline.
///
/// The type of the result.
/// The pipeline.
/// The options.
/// The cancellation token.
/// A cursor.
IAsyncCursor Aggregate(PipelineDefinition pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
///
/// Runs an aggregation pipeline.
///
/// The type of the result.
/// The pipeline.
/// The options.
/// The cancellation token.
/// A Task whose result is a cursor.
Task> AggregateAsync(PipelineDefinition pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
///
/// Performs multiple write operations.
///
/// The requests.
/// The options.
/// The cancellation token.
/// The result of writing.
BulkWriteResult BulkWrite(IEnumerable> requests, BulkWriteOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
///
/// Performs multiple write operations.
///
/// The requests.
/// The options.
/// The cancellation token.
/// The result of writing.
Task> BulkWriteAsync(IEnumerable> requests, BulkWriteOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
///
/// Counts the number of documents in the collection.
///
/// The filter.
/// The options.
/// The cancellation token.
///
/// The number of documents in the collection.
///
long Count(FilterDefinition filter, CountOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
///
/// Counts the number of documents in the collection.
///
/// The filter.
/// The options.
/// The cancellation token.
///
/// The number of documents in the collection.
///
Task CountAsync(FilterDefinition filter, CountOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
///
/// Deletes multiple documents.
///
/// The filter.
/// The cancellation token.
///
/// The result of the delete operation.
///
DeleteResult DeleteMany(FilterDefinition filter, CancellationToken cancellationToken = default(CancellationToken));
///
/// Deletes multiple documents.
///
/// The filter.
/// The options.
/// The cancellation token.
///
/// The result of the delete operation.
///
DeleteResult DeleteMany(FilterDefinition filter, DeleteOptions options, CancellationToken cancellationToken = default(CancellationToken));
///
/// Deletes multiple documents.
///
/// The filter.
/// The cancellation token.
///
/// The result of the delete operation.
///
Task DeleteManyAsync(FilterDefinition filter, CancellationToken cancellationToken = default(CancellationToken));
///
/// Deletes multiple documents.
///
/// The filter.
/// The options.
/// The cancellation token.
///
/// The result of the delete operation.
///
Task DeleteManyAsync(FilterDefinition filter, DeleteOptions options, CancellationToken cancellationToken = default(CancellationToken));
///
/// Deletes a single document.
///
/// The filter.
/// The cancellation token.
///
/// The result of the delete operation.
///
DeleteResult DeleteOne(FilterDefinition filter, CancellationToken cancellationToken = default(CancellationToken));
///
/// Deletes a single document.
///
/// The filter.
/// The options.
/// The cancellation token.
///
/// The result of the delete operation.
///
DeleteResult DeleteOne(FilterDefinition filter, DeleteOptions options, CancellationToken cancellationToken = default(CancellationToken));
///
/// Deletes a single document.
///
/// The filter.
/// The cancellation token.
///
/// The result of the delete operation.
///
Task DeleteOneAsync(FilterDefinition filter, CancellationToken cancellationToken = default(CancellationToken));
///
/// Deletes a single document.
///
/// The filter.
/// The options.
/// The cancellation token.
///
/// The result of the delete operation.
///
Task DeleteOneAsync(FilterDefinition filter, DeleteOptions options, CancellationToken cancellationToken = default(CancellationToken));
///
/// Gets the distinct values for a specified field.
///
/// The type of the result.
/// The field.
/// The filter.
/// The options.
/// The cancellation token.
/// A cursor.
IAsyncCursor Distinct(FieldDefinition field, FilterDefinition filter, DistinctOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
///
/// Gets the distinct values for a specified field.
///
/// The type of the result.
/// The field.
/// The filter.
/// The options.
/// The cancellation token.
/// A Task whose result is a cursor.
Task> DistinctAsync(FieldDefinition field, FilterDefinition filter, DistinctOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
///
/// Finds the documents matching the filter.
///
/// The type of the projection (same as TDocument if there is no projection).
/// The filter.
/// The options.
/// The cancellation token.
/// A cursor.
IAsyncCursor FindSync(FilterDefinition filter, FindOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
///
/// Finds the documents matching the filter.
///
/// The type of the projection (same as TDocument if there is no projection).
/// The filter.
/// The options.
/// The cancellation token.
/// A Task whose result is a cursor.
Task> FindAsync(FilterDefinition filter, FindOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
///
/// Finds a single document and deletes it atomically.
///
/// The type of the projection (same as TDocument if there is no projection).
/// The filter.
/// The options.
/// The cancellation token.
///
/// The returned document.
///
TProjection FindOneAndDelete(FilterDefinition filter, FindOneAndDeleteOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
///
/// Finds a single document and deletes it atomically.
///
/// The type of the projection (same as TDocument if there is no projection).
/// The filter.
/// The options.
/// The cancellation token.
///
/// The returned document.
///
Task FindOneAndDeleteAsync(FilterDefinition filter, FindOneAndDeleteOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
///
/// Finds a single document and replaces it atomically.
///
/// The type of the projection (same as TDocument if there is no projection).
/// The filter.
/// The replacement.
/// The options.
/// The cancellation token.
///
/// The returned document.
///
TProjection FindOneAndReplace(FilterDefinition filter, TDocument replacement, FindOneAndReplaceOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
///
/// Finds a single document and replaces it atomically.
///
/// The type of the projection (same as TDocument if there is no projection).
/// The filter.
/// The replacement.
/// The options.
/// The cancellation token.
///
/// The returned document.
///
Task FindOneAndReplaceAsync(FilterDefinition filter, TDocument replacement, FindOneAndReplaceOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
///
/// Finds a single document and updates it atomically.
///
/// The type of the projection (same as TDocument if there is no projection).
/// The filter.
/// The update.
/// The options.
/// The cancellation token.
///
/// The returned document.
///
TProjection FindOneAndUpdate(FilterDefinition filter, UpdateDefinition update, FindOneAndUpdateOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
///
/// Finds a single document and updates it atomically.
///
/// The type of the projection (same as TDocument if there is no projection).
/// The filter.
/// The update.
/// The options.
/// The cancellation token.
///
/// The returned document.
///
Task FindOneAndUpdateAsync(FilterDefinition filter, UpdateDefinition update, FindOneAndUpdateOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
///
/// Inserts a single document.
///
/// The document.
/// The options.
/// The cancellation token.
void InsertOne(TDocument document, InsertOneOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
///
/// Inserts a single document.
///
/// The document.
/// The cancellation token.
///
/// The result of the insert operation.
///
[Obsolete("Use the new overload of InsertOneAsync with an InsertOneOptions parameter instead.")]
Task InsertOneAsync(TDocument document, CancellationToken _cancellationToken);
///
/// Inserts a single document.
///
/// The document.
/// The options.
/// The cancellation token.
///
/// The result of the insert operation.
///
Task InsertOneAsync(TDocument document, InsertOneOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
///
/// Inserts many documents.
///
/// The documents.
/// The options.
/// The cancellation token.
void InsertMany(IEnumerable documents, InsertManyOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
///
/// Inserts many documents.
///
/// The documents.
/// The options.
/// The cancellation token.
///
/// The result of the insert operation.
///
Task InsertManyAsync(IEnumerable documents, InsertManyOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
///
/// Executes a map-reduce command.
///
/// The type of the result.
/// The map function.
/// The reduce function.
/// The options.
/// The cancellation token.
/// A cursor.
IAsyncCursor MapReduce(BsonJavaScript map, BsonJavaScript reduce, MapReduceOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
///
/// Executes a map-reduce command.
///
/// The type of the result.
/// The map function.
/// The reduce function.
/// The options.
/// The cancellation token.
/// A Task whose result is a cursor.
Task> MapReduceAsync(BsonJavaScript map, BsonJavaScript reduce, MapReduceOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
///
/// Returns a filtered collection that appears to contain only documents of the derived type.
/// All operations using this filtered collection will automatically use discriminators as necessary.
///
/// The type of the derived document.
/// A filtered collection.
IFilteredMongoCollection OfType() where TDerivedDocument : TDocument;
///
/// Replaces a single document.
///
/// The filter.
/// The replacement.
/// The options.
/// The cancellation token.
///
/// The result of the replacement.
///
ReplaceOneResult ReplaceOne(FilterDefinition filter, TDocument replacement, UpdateOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
///
/// Replaces a single document.
///
/// The filter.
/// The replacement.
/// The options.
/// The cancellation token.
///
/// The result of the replacement.
///
Task ReplaceOneAsync(FilterDefinition filter, TDocument replacement, UpdateOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
///
/// Updates many documents.
///
/// The filter.
/// The update.
/// The options.
/// The cancellation token.
///
/// The result of the update operation.
///
UpdateResult UpdateMany(FilterDefinition filter, UpdateDefinition update, UpdateOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
///
/// Updates many documents.
///
/// The filter.
/// The update.
/// The options.
/// The cancellation token.
///
/// The result of the update operation.
///
Task UpdateManyAsync(FilterDefinition filter, UpdateDefinition update, UpdateOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
///
/// Updates a single document.
///
/// The filter.
/// The update.
/// The options.
/// The cancellation token.
///
/// The result of the update operation.
///
UpdateResult UpdateOne(FilterDefinition filter, UpdateDefinition update, UpdateOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
///
/// Updates a single document.
///
/// The filter.
/// The update.
/// The options.
/// The cancellation token.
///
/// The result of the update operation.
///
Task UpdateOneAsync(FilterDefinition filter, UpdateDefinition update, UpdateOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
///
/// Returns a new IMongoCollection instance with a different read concern setting.
///
/// The read concern.
/// A new IMongoCollection instance with a different read concern setting.
IMongoCollection WithReadConcern(ReadConcern readConcern);
///
/// Returns a new IMongoCollection instance with a different read preference setting.
///
/// The read preference.
/// A new IMongoCollection instance with a different read preference setting.
IMongoCollection WithReadPreference(ReadPreference readPreference);
///
/// Returns a new IMongoCollection instance with a different write concern setting.
///
/// The write concern.
/// A new IMongoCollection instance with a different write concern setting.
IMongoCollection WithWriteConcern(WriteConcern writeConcern);
}
}