Interface IMongoCollection<TDocument>
Represents a typed collection in MongoDB.
public interface IMongoCollection<TDocument>
Type Parameters
TDocument
The type of the documents stored in the collection.
- Extension Methods
Remarks
This interface is not guaranteed to remain stable. Implementors should use MongoCollectionBase<TDocument>.
Properties
CollectionNamespace
Gets the namespace of the collection.
CollectionNamespace CollectionNamespace { get; }
Property Value
Database
Gets the database.
IMongoDatabase Database { get; }
Property Value
DocumentSerializer
Gets the document serializer.
IBsonSerializer<TDocument> DocumentSerializer { get; }
Property Value
- IBsonSerializer<TDocument>
Indexes
Gets the index manager.
IMongoIndexManager<TDocument> Indexes { get; }
Property Value
- IMongoIndexManager<TDocument>
SearchIndexes
Gets the search index manager.
IMongoSearchIndexManager SearchIndexes { get; }
Property Value
Settings
Gets the settings.
MongoCollectionSettings Settings { get; }
Property Value
Methods
AggregateAsync<TResult>(IClientSessionHandle, PipelineDefinition<TDocument, TResult>, AggregateOptions, CancellationToken)
Runs an aggregation pipeline.
Task<IAsyncCursor<TResult>> AggregateAsync<TResult>(IClientSessionHandle session, PipelineDefinition<TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
pipeline
PipelineDefinition<TDocument, TResult>The pipeline.
options
AggregateOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<IAsyncCursor<TResult>>
A Task whose result is a cursor.
Type Parameters
TResult
The type of the result.
AggregateAsync<TResult>(PipelineDefinition<TDocument, TResult>, AggregateOptions, CancellationToken)
Runs an aggregation pipeline.
Task<IAsyncCursor<TResult>> AggregateAsync<TResult>(PipelineDefinition<TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default)
Parameters
pipeline
PipelineDefinition<TDocument, TResult>The pipeline.
options
AggregateOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<IAsyncCursor<TResult>>
A Task whose result is a cursor.
Type Parameters
TResult
The type of the result.
AggregateToCollectionAsync<TResult>(IClientSessionHandle, PipelineDefinition<TDocument, TResult>, AggregateOptions, CancellationToken)
Runs an aggregation pipeline whose results are written to a collection.
Task AggregateToCollectionAsync<TResult>(IClientSessionHandle session, PipelineDefinition<TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
pipeline
PipelineDefinition<TDocument, TResult>The pipeline.
options
AggregateOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task
A Task.
Type Parameters
TResult
The type of the result.
AggregateToCollectionAsync<TResult>(PipelineDefinition<TDocument, TResult>, AggregateOptions, CancellationToken)
Runs an aggregation pipeline whose results are written to a collection.
Task AggregateToCollectionAsync<TResult>(PipelineDefinition<TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default)
Parameters
pipeline
PipelineDefinition<TDocument, TResult>The pipeline.
options
AggregateOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task
A Task.
Type Parameters
TResult
The type of the result.
AggregateToCollection<TResult>(IClientSessionHandle, PipelineDefinition<TDocument, TResult>, AggregateOptions, CancellationToken)
Runs an aggregation pipeline whose results are written to a collection.
void AggregateToCollection<TResult>(IClientSessionHandle session, PipelineDefinition<TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
pipeline
PipelineDefinition<TDocument, TResult>The pipeline.
options
AggregateOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Type Parameters
TResult
The type of the result.
AggregateToCollection<TResult>(PipelineDefinition<TDocument, TResult>, AggregateOptions, CancellationToken)
Runs an aggregation pipeline whose results are written to a collection.
void AggregateToCollection<TResult>(PipelineDefinition<TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default)
Parameters
pipeline
PipelineDefinition<TDocument, TResult>The pipeline.
options
AggregateOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Type Parameters
TResult
The type of the result.
Aggregate<TResult>(IClientSessionHandle, PipelineDefinition<TDocument, TResult>, AggregateOptions, CancellationToken)
Runs an aggregation pipeline.
IAsyncCursor<TResult> Aggregate<TResult>(IClientSessionHandle session, PipelineDefinition<TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
pipeline
PipelineDefinition<TDocument, TResult>The pipeline.
options
AggregateOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- IAsyncCursor<TResult>
A cursor.
Type Parameters
TResult
The type of the result.
Aggregate<TResult>(PipelineDefinition<TDocument, TResult>, AggregateOptions, CancellationToken)
Runs an aggregation pipeline.
IAsyncCursor<TResult> Aggregate<TResult>(PipelineDefinition<TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default)
Parameters
pipeline
PipelineDefinition<TDocument, TResult>The pipeline.
options
AggregateOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- IAsyncCursor<TResult>
A cursor.
Type Parameters
TResult
The type of the result.
BulkWrite(IClientSessionHandle, IEnumerable<WriteModel<TDocument>>, BulkWriteOptions, CancellationToken)
Performs multiple write operations.
BulkWriteResult<TDocument> BulkWrite(IClientSessionHandle session, IEnumerable<WriteModel<TDocument>> requests, BulkWriteOptions options = null, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
requests
IEnumerable<WriteModel<TDocument>>The requests.
options
BulkWriteOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- BulkWriteResult<TDocument>
The result of writing.
BulkWrite(IEnumerable<WriteModel<TDocument>>, BulkWriteOptions, CancellationToken)
Performs multiple write operations.
BulkWriteResult<TDocument> BulkWrite(IEnumerable<WriteModel<TDocument>> requests, BulkWriteOptions options = null, CancellationToken cancellationToken = default)
Parameters
requests
IEnumerable<WriteModel<TDocument>>The requests.
options
BulkWriteOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- BulkWriteResult<TDocument>
The result of writing.
BulkWriteAsync(IClientSessionHandle, IEnumerable<WriteModel<TDocument>>, BulkWriteOptions, CancellationToken)
Performs multiple write operations.
Task<BulkWriteResult<TDocument>> BulkWriteAsync(IClientSessionHandle session, IEnumerable<WriteModel<TDocument>> requests, BulkWriteOptions options = null, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
requests
IEnumerable<WriteModel<TDocument>>The requests.
options
BulkWriteOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<BulkWriteResult<TDocument>>
The result of writing.
BulkWriteAsync(IEnumerable<WriteModel<TDocument>>, BulkWriteOptions, CancellationToken)
Performs multiple write operations.
Task<BulkWriteResult<TDocument>> BulkWriteAsync(IEnumerable<WriteModel<TDocument>> requests, BulkWriteOptions options = null, CancellationToken cancellationToken = default)
Parameters
requests
IEnumerable<WriteModel<TDocument>>The requests.
options
BulkWriteOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<BulkWriteResult<TDocument>>
The result of writing.
Count(FilterDefinition<TDocument>, CountOptions, CancellationToken)
Counts the number of documents in the collection.
[Obsolete("Use CountDocuments or EstimatedDocumentCount instead.")]
long Count(FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default)
Parameters
filter
FilterDefinition<TDocument>The filter.
options
CountOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- long
The number of documents in the collection.
Count(IClientSessionHandle, FilterDefinition<TDocument>, CountOptions, CancellationToken)
Counts the number of documents in the collection.
[Obsolete("Use CountDocuments or EstimatedDocumentCount instead.")]
long Count(IClientSessionHandle session, FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
filter
FilterDefinition<TDocument>The filter.
options
CountOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- long
The number of documents in the collection.
CountAsync(FilterDefinition<TDocument>, CountOptions, CancellationToken)
Counts the number of documents in the collection.
[Obsolete("Use CountDocumentsAsync or EstimatedDocumentCountAsync instead.")]
Task<long> CountAsync(FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default)
Parameters
filter
FilterDefinition<TDocument>The filter.
options
CountOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
CountAsync(IClientSessionHandle, FilterDefinition<TDocument>, CountOptions, CancellationToken)
Counts the number of documents in the collection.
[Obsolete("Use CountDocumentsAsync or EstimatedDocumentCountAsync instead.")]
Task<long> CountAsync(IClientSessionHandle session, FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
filter
FilterDefinition<TDocument>The filter.
options
CountOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
CountDocuments(FilterDefinition<TDocument>, CountOptions, CancellationToken)
Counts the number of documents in the collection. For a fast estimate of the total documents in a collection see EstimatedDocumentCount(EstimatedDocumentCountOptions, CancellationToken).
long CountDocuments(FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default)
Parameters
filter
FilterDefinition<TDocument>The filter.
options
CountOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- long
The number of documents in the collection.
Remarks
Note: when migrating from Count to CountDocuments the following query operations must be replaced:
+-------------+--------------------------------+
| Operator | Replacement |
+=============+================================+
| $where | $expr |
+-------------+--------------------------------+
| $near | $geoWithin with $center |
+-------------+--------------------------------+
| $nearSphere | $geoWithin with $centerSphere |
+-------------+--------------------------------+
CountDocuments(IClientSessionHandle, FilterDefinition<TDocument>, CountOptions, CancellationToken)
Counts the number of documents in the collection. For a fast estimate of the total documents in a collection see EstimatedDocumentCount(EstimatedDocumentCountOptions, CancellationToken).
long CountDocuments(IClientSessionHandle session, FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
filter
FilterDefinition<TDocument>The filter.
options
CountOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- long
The number of documents in the collection.
Remarks
Note: when migrating from Count to CountDocuments the following query operations must be replaced:
+-------------+--------------------------------+
| Operator | Replacement |
+=============+================================+
| $where | $expr |
+-------------+--------------------------------+
| $near | $geoWithin with $center |
+-------------+--------------------------------+
| $nearSphere | $geoWithin with $centerSphere |
+-------------+--------------------------------+
CountDocumentsAsync(FilterDefinition<TDocument>, CountOptions, CancellationToken)
Counts the number of documents in the collection.
For a fast estimate of the total documents in a collection see
Task<long> CountDocumentsAsync(FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default)
Parameters
filter
FilterDefinition<TDocument>The filter.
options
CountOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
Remarks
Note: when migrating from CountAsync to CountDocumentsAsync the following query operations must be replaced:
+-------------+--------------------------------+
| Operator | Replacement |
+=============+================================+
| $where | $expr |
+-------------+--------------------------------+
| $near | $geoWithin with $center |
+-------------+--------------------------------+
| $nearSphere | $geoWithin with $centerSphere |
+-------------+--------------------------------+
CountDocumentsAsync(IClientSessionHandle, FilterDefinition<TDocument>, CountOptions, CancellationToken)
Counts the number of documents in the collection. For a fast estimate of the total documents in a collection see EstimatedDocumentCountAsync(EstimatedDocumentCountOptions, CancellationToken).
Task<long> CountDocumentsAsync(IClientSessionHandle session, FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
filter
FilterDefinition<TDocument>The filter.
options
CountOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
Remarks
Note: when migrating from CountAsync to CountDocumentsAsync the following query operations must be replaced:
+-------------+--------------------------------+
| Operator | Replacement |
+=============+================================+
| $where | $expr |
+-------------+--------------------------------+
| $near | $geoWithin with $center |
+-------------+--------------------------------+
| $nearSphere | $geoWithin with $centerSphere |
+-------------+--------------------------------+
DeleteMany(FilterDefinition<TDocument>, DeleteOptions, CancellationToken)
Deletes multiple documents.
DeleteResult DeleteMany(FilterDefinition<TDocument> filter, DeleteOptions options, CancellationToken cancellationToken = default)
Parameters
filter
FilterDefinition<TDocument>The filter.
options
DeleteOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- DeleteResult
The result of the delete operation.
DeleteMany(FilterDefinition<TDocument>, CancellationToken)
Deletes multiple documents.
DeleteResult DeleteMany(FilterDefinition<TDocument> filter, CancellationToken cancellationToken = default)
Parameters
filter
FilterDefinition<TDocument>The filter.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- DeleteResult
The result of the delete operation.
DeleteMany(IClientSessionHandle, FilterDefinition<TDocument>, DeleteOptions, CancellationToken)
Deletes multiple documents.
DeleteResult DeleteMany(IClientSessionHandle session, FilterDefinition<TDocument> filter, DeleteOptions options = null, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
filter
FilterDefinition<TDocument>The filter.
options
DeleteOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- DeleteResult
The result of the delete operation.
DeleteManyAsync(FilterDefinition<TDocument>, DeleteOptions, CancellationToken)
Deletes multiple documents.
Task<DeleteResult> DeleteManyAsync(FilterDefinition<TDocument> filter, DeleteOptions options, CancellationToken cancellationToken = default)
Parameters
filter
FilterDefinition<TDocument>The filter.
options
DeleteOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<DeleteResult>
The result of the delete operation.
DeleteManyAsync(FilterDefinition<TDocument>, CancellationToken)
Deletes multiple documents.
Task<DeleteResult> DeleteManyAsync(FilterDefinition<TDocument> filter, CancellationToken cancellationToken = default)
Parameters
filter
FilterDefinition<TDocument>The filter.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<DeleteResult>
The result of the delete operation.
DeleteManyAsync(IClientSessionHandle, FilterDefinition<TDocument>, DeleteOptions, CancellationToken)
Deletes multiple documents.
Task<DeleteResult> DeleteManyAsync(IClientSessionHandle session, FilterDefinition<TDocument> filter, DeleteOptions options = null, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
filter
FilterDefinition<TDocument>The filter.
options
DeleteOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<DeleteResult>
The result of the delete operation.
DeleteOne(FilterDefinition<TDocument>, DeleteOptions, CancellationToken)
Deletes a single document.
DeleteResult DeleteOne(FilterDefinition<TDocument> filter, DeleteOptions options, CancellationToken cancellationToken = default)
Parameters
filter
FilterDefinition<TDocument>The filter.
options
DeleteOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- DeleteResult
The result of the delete operation.
DeleteOne(FilterDefinition<TDocument>, CancellationToken)
Deletes a single document.
DeleteResult DeleteOne(FilterDefinition<TDocument> filter, CancellationToken cancellationToken = default)
Parameters
filter
FilterDefinition<TDocument>The filter.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- DeleteResult
The result of the delete operation.
DeleteOne(IClientSessionHandle, FilterDefinition<TDocument>, DeleteOptions, CancellationToken)
Deletes a single document.
DeleteResult DeleteOne(IClientSessionHandle session, FilterDefinition<TDocument> filter, DeleteOptions options = null, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
filter
FilterDefinition<TDocument>The filter.
options
DeleteOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- DeleteResult
The result of the delete operation.
DeleteOneAsync(FilterDefinition<TDocument>, DeleteOptions, CancellationToken)
Deletes a single document.
Task<DeleteResult> DeleteOneAsync(FilterDefinition<TDocument> filter, DeleteOptions options, CancellationToken cancellationToken = default)
Parameters
filter
FilterDefinition<TDocument>The filter.
options
DeleteOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<DeleteResult>
The result of the delete operation.
DeleteOneAsync(FilterDefinition<TDocument>, CancellationToken)
Deletes a single document.
Task<DeleteResult> DeleteOneAsync(FilterDefinition<TDocument> filter, CancellationToken cancellationToken = default)
Parameters
filter
FilterDefinition<TDocument>The filter.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<DeleteResult>
The result of the delete operation.
DeleteOneAsync(IClientSessionHandle, FilterDefinition<TDocument>, DeleteOptions, CancellationToken)
Deletes a single document.
Task<DeleteResult> DeleteOneAsync(IClientSessionHandle session, FilterDefinition<TDocument> filter, DeleteOptions options = null, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
filter
FilterDefinition<TDocument>The filter.
options
DeleteOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<DeleteResult>
The result of the delete operation.
DistinctAsync<TField>(FieldDefinition<TDocument, TField>, FilterDefinition<TDocument>, DistinctOptions, CancellationToken)
Gets the distinct values for a specified field.
Task<IAsyncCursor<TField>> DistinctAsync<TField>(FieldDefinition<TDocument, TField> field, FilterDefinition<TDocument> filter, DistinctOptions options = null, CancellationToken cancellationToken = default)
Parameters
field
FieldDefinition<TDocument, TField>The field.
filter
FilterDefinition<TDocument>The filter.
options
DistinctOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<IAsyncCursor<TField>>
A Task whose result is a cursor.
Type Parameters
TField
The type of the result.
DistinctAsync<TField>(IClientSessionHandle, FieldDefinition<TDocument, TField>, FilterDefinition<TDocument>, DistinctOptions, CancellationToken)
Gets the distinct values for a specified field.
Task<IAsyncCursor<TField>> DistinctAsync<TField>(IClientSessionHandle session, FieldDefinition<TDocument, TField> field, FilterDefinition<TDocument> filter, DistinctOptions options = null, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
field
FieldDefinition<TDocument, TField>The field.
filter
FilterDefinition<TDocument>The filter.
options
DistinctOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<IAsyncCursor<TField>>
A Task whose result is a cursor.
Type Parameters
TField
The type of the result.
Distinct<TField>(FieldDefinition<TDocument, TField>, FilterDefinition<TDocument>, DistinctOptions, CancellationToken)
Gets the distinct values for a specified field.
IAsyncCursor<TField> Distinct<TField>(FieldDefinition<TDocument, TField> field, FilterDefinition<TDocument> filter, DistinctOptions options = null, CancellationToken cancellationToken = default)
Parameters
field
FieldDefinition<TDocument, TField>The field.
filter
FilterDefinition<TDocument>The filter.
options
DistinctOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- IAsyncCursor<TField>
A cursor.
Type Parameters
TField
The type of the result.
Distinct<TField>(IClientSessionHandle, FieldDefinition<TDocument, TField>, FilterDefinition<TDocument>, DistinctOptions, CancellationToken)
Gets the distinct values for a specified field.
IAsyncCursor<TField> Distinct<TField>(IClientSessionHandle session, FieldDefinition<TDocument, TField> field, FilterDefinition<TDocument> filter, DistinctOptions options = null, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
field
FieldDefinition<TDocument, TField>The field.
filter
FilterDefinition<TDocument>The filter.
options
DistinctOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- IAsyncCursor<TField>
A cursor.
Type Parameters
TField
The type of the result.
EstimatedDocumentCount(EstimatedDocumentCountOptions, CancellationToken)
Returns an estimate of the number of documents in the collection.
long EstimatedDocumentCount(EstimatedDocumentCountOptions options = null, CancellationToken cancellationToken = default)
Parameters
options
EstimatedDocumentCountOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- long
An estimate of the number of documents in the collection.
Remarks
Due to an oversight in versions 5.0.0-5.0.8 of MongoDB, the count command, which estimatedDocumentCount uses in its implementation, was not included in v1 of the Stable API. If you are using the Stable API with estimatedDocumentCount, you must upgrade to server version 5.0.9+ or set strict: false when configuring ServerApi to avoid encountering errors.
EstimatedDocumentCountAsync(EstimatedDocumentCountOptions, CancellationToken)
Returns an estimate of the number of documents in the collection.
Task<long> EstimatedDocumentCountAsync(EstimatedDocumentCountOptions options = null, CancellationToken cancellationToken = default)
Parameters
options
EstimatedDocumentCountOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
FindAsync<TProjection>(FilterDefinition<TDocument>, FindOptions<TDocument, TProjection>, CancellationToken)
Finds the documents matching the filter.
Task<IAsyncCursor<TProjection>> FindAsync<TProjection>(FilterDefinition<TDocument> filter, FindOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default)
Parameters
filter
FilterDefinition<TDocument>The filter.
options
FindOptions<TDocument, TProjection>The options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<IAsyncCursor<TProjection>>
A Task whose result is a cursor.
Type Parameters
TProjection
The type of the projection (same as TDocument if there is no projection).
FindAsync<TProjection>(IClientSessionHandle, FilterDefinition<TDocument>, FindOptions<TDocument, TProjection>, CancellationToken)
Finds the documents matching the filter.
Task<IAsyncCursor<TProjection>> FindAsync<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, FindOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
filter
FilterDefinition<TDocument>The filter.
options
FindOptions<TDocument, TProjection>The options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<IAsyncCursor<TProjection>>
A Task whose result is a cursor.
Type Parameters
TProjection
The type of the projection (same as TDocument if there is no projection).
FindOneAndDeleteAsync<TProjection>(FilterDefinition<TDocument>, FindOneAndDeleteOptions<TDocument, TProjection>, CancellationToken)
Finds a single document and deletes it atomically.
Task<TProjection> FindOneAndDeleteAsync<TProjection>(FilterDefinition<TDocument> filter, FindOneAndDeleteOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default)
Parameters
filter
FilterDefinition<TDocument>The filter.
options
FindOneAndDeleteOptions<TDocument, TProjection>The options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<TProjection>
The returned document.
Type Parameters
TProjection
The type of the projection (same as TDocument if there is no projection).
FindOneAndDeleteAsync<TProjection>(IClientSessionHandle, FilterDefinition<TDocument>, FindOneAndDeleteOptions<TDocument, TProjection>, CancellationToken)
Finds a single document and deletes it atomically.
Task<TProjection> FindOneAndDeleteAsync<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, FindOneAndDeleteOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
filter
FilterDefinition<TDocument>The filter.
options
FindOneAndDeleteOptions<TDocument, TProjection>The options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<TProjection>
The returned document.
Type Parameters
TProjection
The type of the projection (same as TDocument if there is no projection).
FindOneAndDelete<TProjection>(FilterDefinition<TDocument>, FindOneAndDeleteOptions<TDocument, TProjection>, CancellationToken)
Finds a single document and deletes it atomically.
TProjection FindOneAndDelete<TProjection>(FilterDefinition<TDocument> filter, FindOneAndDeleteOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default)
Parameters
filter
FilterDefinition<TDocument>The filter.
options
FindOneAndDeleteOptions<TDocument, TProjection>The options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- TProjection
The returned document.
Type Parameters
TProjection
The type of the projection (same as TDocument if there is no projection).
FindOneAndDelete<TProjection>(IClientSessionHandle, FilterDefinition<TDocument>, FindOneAndDeleteOptions<TDocument, TProjection>, CancellationToken)
Finds a single document and deletes it atomically.
TProjection FindOneAndDelete<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, FindOneAndDeleteOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
filter
FilterDefinition<TDocument>The filter.
options
FindOneAndDeleteOptions<TDocument, TProjection>The options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- TProjection
The returned document.
Type Parameters
TProjection
The type of the projection (same as TDocument if there is no projection).
FindOneAndReplaceAsync<TProjection>(FilterDefinition<TDocument>, TDocument, FindOneAndReplaceOptions<TDocument, TProjection>, CancellationToken)
Finds a single document and replaces it atomically.
Task<TProjection> FindOneAndReplaceAsync<TProjection>(FilterDefinition<TDocument> filter, TDocument replacement, FindOneAndReplaceOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default)
Parameters
filter
FilterDefinition<TDocument>The filter.
replacement
TDocumentThe replacement.
options
FindOneAndReplaceOptions<TDocument, TProjection>The options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<TProjection>
The returned document.
Type Parameters
TProjection
The type of the projection (same as TDocument if there is no projection).
FindOneAndReplaceAsync<TProjection>(IClientSessionHandle, FilterDefinition<TDocument>, TDocument, FindOneAndReplaceOptions<TDocument, TProjection>, CancellationToken)
Finds a single document and replaces it atomically.
Task<TProjection> FindOneAndReplaceAsync<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, TDocument replacement, FindOneAndReplaceOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
filter
FilterDefinition<TDocument>The filter.
replacement
TDocumentThe replacement.
options
FindOneAndReplaceOptions<TDocument, TProjection>The options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<TProjection>
The returned document.
Type Parameters
TProjection
The type of the projection (same as TDocument if there is no projection).
FindOneAndReplace<TProjection>(FilterDefinition<TDocument>, TDocument, FindOneAndReplaceOptions<TDocument, TProjection>, CancellationToken)
Finds a single document and replaces it atomically.
TProjection FindOneAndReplace<TProjection>(FilterDefinition<TDocument> filter, TDocument replacement, FindOneAndReplaceOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default)
Parameters
filter
FilterDefinition<TDocument>The filter.
replacement
TDocumentThe replacement.
options
FindOneAndReplaceOptions<TDocument, TProjection>The options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- TProjection
The returned document.
Type Parameters
TProjection
The type of the projection (same as TDocument if there is no projection).
FindOneAndReplace<TProjection>(IClientSessionHandle, FilterDefinition<TDocument>, TDocument, FindOneAndReplaceOptions<TDocument, TProjection>, CancellationToken)
Finds a single document and replaces it atomically.
TProjection FindOneAndReplace<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, TDocument replacement, FindOneAndReplaceOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
filter
FilterDefinition<TDocument>The filter.
replacement
TDocumentThe replacement.
options
FindOneAndReplaceOptions<TDocument, TProjection>The options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- TProjection
The returned document.
Type Parameters
TProjection
The type of the projection (same as TDocument if there is no projection).
FindOneAndUpdateAsync<TProjection>(FilterDefinition<TDocument>, UpdateDefinition<TDocument>, FindOneAndUpdateOptions<TDocument, TProjection>, CancellationToken)
Finds a single document and updates it atomically.
Task<TProjection> FindOneAndUpdateAsync<TProjection>(FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, FindOneAndUpdateOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default)
Parameters
filter
FilterDefinition<TDocument>The filter.
update
UpdateDefinition<TDocument>The update.
options
FindOneAndUpdateOptions<TDocument, TProjection>The options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<TProjection>
The returned document.
Type Parameters
TProjection
The type of the projection (same as TDocument if there is no projection).
FindOneAndUpdateAsync<TProjection>(IClientSessionHandle, FilterDefinition<TDocument>, UpdateDefinition<TDocument>, FindOneAndUpdateOptions<TDocument, TProjection>, CancellationToken)
Finds a single document and updates it atomically.
Task<TProjection> FindOneAndUpdateAsync<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, FindOneAndUpdateOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
filter
FilterDefinition<TDocument>The filter.
update
UpdateDefinition<TDocument>The update.
options
FindOneAndUpdateOptions<TDocument, TProjection>The options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<TProjection>
The returned document.
Type Parameters
TProjection
The type of the projection (same as TDocument if there is no projection).
FindOneAndUpdate<TProjection>(FilterDefinition<TDocument>, UpdateDefinition<TDocument>, FindOneAndUpdateOptions<TDocument, TProjection>, CancellationToken)
Finds a single document and updates it atomically.
TProjection FindOneAndUpdate<TProjection>(FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, FindOneAndUpdateOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default)
Parameters
filter
FilterDefinition<TDocument>The filter.
update
UpdateDefinition<TDocument>The update.
options
FindOneAndUpdateOptions<TDocument, TProjection>The options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- TProjection
The returned document.
Type Parameters
TProjection
The type of the projection (same as TDocument if there is no projection).
FindOneAndUpdate<TProjection>(IClientSessionHandle, FilterDefinition<TDocument>, UpdateDefinition<TDocument>, FindOneAndUpdateOptions<TDocument, TProjection>, CancellationToken)
Finds a single document and updates it atomically.
TProjection FindOneAndUpdate<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, FindOneAndUpdateOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
filter
FilterDefinition<TDocument>The filter.
update
UpdateDefinition<TDocument>The update.
options
FindOneAndUpdateOptions<TDocument, TProjection>The options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- TProjection
The returned document.
Type Parameters
TProjection
The type of the projection (same as TDocument if there is no projection).
FindSync<TProjection>(FilterDefinition<TDocument>, FindOptions<TDocument, TProjection>, CancellationToken)
Finds the documents matching the filter.
IAsyncCursor<TProjection> FindSync<TProjection>(FilterDefinition<TDocument> filter, FindOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default)
Parameters
filter
FilterDefinition<TDocument>The filter.
options
FindOptions<TDocument, TProjection>The options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- IAsyncCursor<TProjection>
A cursor.
Type Parameters
TProjection
The type of the projection (same as TDocument if there is no projection).
FindSync<TProjection>(IClientSessionHandle, FilterDefinition<TDocument>, FindOptions<TDocument, TProjection>, CancellationToken)
Finds the documents matching the filter.
IAsyncCursor<TProjection> FindSync<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, FindOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
filter
FilterDefinition<TDocument>The filter.
options
FindOptions<TDocument, TProjection>The options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- IAsyncCursor<TProjection>
A cursor.
Type Parameters
TProjection
The type of the projection (same as TDocument if there is no projection).
InsertMany(IClientSessionHandle, IEnumerable<TDocument>, InsertManyOptions, CancellationToken)
Inserts many documents.
void InsertMany(IClientSessionHandle session, IEnumerable<TDocument> documents, InsertManyOptions options = null, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
documents
IEnumerable<TDocument>The documents.
options
InsertManyOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
InsertMany(IEnumerable<TDocument>, InsertManyOptions, CancellationToken)
Inserts many documents.
void InsertMany(IEnumerable<TDocument> documents, InsertManyOptions options = null, CancellationToken cancellationToken = default)
Parameters
documents
IEnumerable<TDocument>The documents.
options
InsertManyOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
InsertManyAsync(IClientSessionHandle, IEnumerable<TDocument>, InsertManyOptions, CancellationToken)
Inserts many documents.
Task InsertManyAsync(IClientSessionHandle session, IEnumerable<TDocument> documents, InsertManyOptions options = null, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
documents
IEnumerable<TDocument>The documents.
options
InsertManyOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task
The result of the insert operation.
InsertManyAsync(IEnumerable<TDocument>, InsertManyOptions, CancellationToken)
Inserts many documents.
Task InsertManyAsync(IEnumerable<TDocument> documents, InsertManyOptions options = null, CancellationToken cancellationToken = default)
Parameters
documents
IEnumerable<TDocument>The documents.
options
InsertManyOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task
The result of the insert operation.
InsertOne(IClientSessionHandle, TDocument, InsertOneOptions, CancellationToken)
Inserts a single document.
void InsertOne(IClientSessionHandle session, TDocument document, InsertOneOptions options = null, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
document
TDocumentThe document.
options
InsertOneOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
InsertOne(TDocument, InsertOneOptions, CancellationToken)
Inserts a single document.
void InsertOne(TDocument document, InsertOneOptions options = null, CancellationToken cancellationToken = default)
Parameters
document
TDocumentThe document.
options
InsertOneOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
InsertOneAsync(IClientSessionHandle, TDocument, InsertOneOptions, CancellationToken)
Inserts a single document.
Task InsertOneAsync(IClientSessionHandle session, TDocument document, InsertOneOptions options = null, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
document
TDocumentThe document.
options
InsertOneOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task
The result of the insert operation.
InsertOneAsync(TDocument, InsertOneOptions, CancellationToken)
Inserts a single document.
Task InsertOneAsync(TDocument document, InsertOneOptions options = null, CancellationToken cancellationToken = default)
Parameters
document
TDocumentThe document.
options
InsertOneOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task
The result of the insert operation.
InsertOneAsync(TDocument, CancellationToken)
Inserts a single document.
[Obsolete("Use the new overload of InsertOneAsync with an InsertOneOptions parameter instead.")]
Task InsertOneAsync(TDocument document, CancellationToken _cancellationToken)
Parameters
document
TDocumentThe document.
_cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task
The result of the insert operation.
MapReduceAsync<TResult>(BsonJavaScript, BsonJavaScript, MapReduceOptions<TDocument, TResult>, CancellationToken)
Executes a map-reduce command.
[Obsolete("Use Aggregation pipeline instead.")]
Task<IAsyncCursor<TResult>> MapReduceAsync<TResult>(BsonJavaScript map, BsonJavaScript reduce, MapReduceOptions<TDocument, TResult> options = null, CancellationToken cancellationToken = default)
Parameters
map
BsonJavaScriptThe map function.
reduce
BsonJavaScriptThe reduce function.
options
MapReduceOptions<TDocument, TResult>The options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<IAsyncCursor<TResult>>
A Task whose result is a cursor.
Type Parameters
TResult
The type of the result.
MapReduceAsync<TResult>(IClientSessionHandle, BsonJavaScript, BsonJavaScript, MapReduceOptions<TDocument, TResult>, CancellationToken)
Executes a map-reduce command.
[Obsolete("Use Aggregation pipeline instead.")]
Task<IAsyncCursor<TResult>> MapReduceAsync<TResult>(IClientSessionHandle session, BsonJavaScript map, BsonJavaScript reduce, MapReduceOptions<TDocument, TResult> options = null, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
map
BsonJavaScriptThe map function.
reduce
BsonJavaScriptThe reduce function.
options
MapReduceOptions<TDocument, TResult>The options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<IAsyncCursor<TResult>>
A Task whose result is a cursor.
Type Parameters
TResult
The type of the result.
MapReduce<TResult>(BsonJavaScript, BsonJavaScript, MapReduceOptions<TDocument, TResult>, CancellationToken)
Executes a map-reduce command.
[Obsolete("Use Aggregation pipeline instead.")]
IAsyncCursor<TResult> MapReduce<TResult>(BsonJavaScript map, BsonJavaScript reduce, MapReduceOptions<TDocument, TResult> options = null, CancellationToken cancellationToken = default)
Parameters
map
BsonJavaScriptThe map function.
reduce
BsonJavaScriptThe reduce function.
options
MapReduceOptions<TDocument, TResult>The options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- IAsyncCursor<TResult>
A cursor.
Type Parameters
TResult
The type of the result.
MapReduce<TResult>(IClientSessionHandle, BsonJavaScript, BsonJavaScript, MapReduceOptions<TDocument, TResult>, CancellationToken)
Executes a map-reduce command.
[Obsolete("Use Aggregation pipeline instead.")]
IAsyncCursor<TResult> MapReduce<TResult>(IClientSessionHandle session, BsonJavaScript map, BsonJavaScript reduce, MapReduceOptions<TDocument, TResult> options = null, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
map
BsonJavaScriptThe map function.
reduce
BsonJavaScriptThe reduce function.
options
MapReduceOptions<TDocument, TResult>The options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- IAsyncCursor<TResult>
A cursor.
Type Parameters
TResult
The type of the result.
OfType<TDerivedDocument>()
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.
IFilteredMongoCollection<TDerivedDocument> OfType<TDerivedDocument>() where TDerivedDocument : TDocument
Returns
- IFilteredMongoCollection<TDerivedDocument>
A filtered collection.
Type Parameters
TDerivedDocument
The type of the derived document.
ReplaceOne(FilterDefinition<TDocument>, TDocument, ReplaceOptions, CancellationToken)
Replaces a single document.
ReplaceOneResult ReplaceOne(FilterDefinition<TDocument> filter, TDocument replacement, ReplaceOptions options = null, CancellationToken cancellationToken = default)
Parameters
filter
FilterDefinition<TDocument>The filter.
replacement
TDocumentThe replacement.
options
ReplaceOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- ReplaceOneResult
The result of the replacement.
ReplaceOne(FilterDefinition<TDocument>, TDocument, UpdateOptions, CancellationToken)
Replaces a single document.
[Obsolete("Use the overload that takes a ReplaceOptions instead of an UpdateOptions.")]
ReplaceOneResult ReplaceOne(FilterDefinition<TDocument> filter, TDocument replacement, UpdateOptions options, CancellationToken cancellationToken = default)
Parameters
filter
FilterDefinition<TDocument>The filter.
replacement
TDocumentThe replacement.
options
UpdateOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- ReplaceOneResult
The result of the replacement.
ReplaceOne(IClientSessionHandle, FilterDefinition<TDocument>, TDocument, ReplaceOptions, CancellationToken)
Replaces a single document.
ReplaceOneResult ReplaceOne(IClientSessionHandle session, FilterDefinition<TDocument> filter, TDocument replacement, ReplaceOptions options = null, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
filter
FilterDefinition<TDocument>The filter.
replacement
TDocumentThe replacement.
options
ReplaceOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- ReplaceOneResult
The result of the replacement.
ReplaceOne(IClientSessionHandle, FilterDefinition<TDocument>, TDocument, UpdateOptions, CancellationToken)
Replaces a single document.
[Obsolete("Use the overload that takes a ReplaceOptions instead of an UpdateOptions.")]
ReplaceOneResult ReplaceOne(IClientSessionHandle session, FilterDefinition<TDocument> filter, TDocument replacement, UpdateOptions options, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
filter
FilterDefinition<TDocument>The filter.
replacement
TDocumentThe replacement.
options
UpdateOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- ReplaceOneResult
The result of the replacement.
ReplaceOneAsync(FilterDefinition<TDocument>, TDocument, ReplaceOptions, CancellationToken)
Replaces a single document.
Task<ReplaceOneResult> ReplaceOneAsync(FilterDefinition<TDocument> filter, TDocument replacement, ReplaceOptions options = null, CancellationToken cancellationToken = default)
Parameters
filter
FilterDefinition<TDocument>The filter.
replacement
TDocumentThe replacement.
options
ReplaceOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<ReplaceOneResult>
The result of the replacement.
ReplaceOneAsync(FilterDefinition<TDocument>, TDocument, UpdateOptions, CancellationToken)
Replaces a single document.
[Obsolete("Use the overload that takes a ReplaceOptions instead of an UpdateOptions.")]
Task<ReplaceOneResult> ReplaceOneAsync(FilterDefinition<TDocument> filter, TDocument replacement, UpdateOptions options, CancellationToken cancellationToken = default)
Parameters
filter
FilterDefinition<TDocument>The filter.
replacement
TDocumentThe replacement.
options
UpdateOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<ReplaceOneResult>
The result of the replacement.
ReplaceOneAsync(IClientSessionHandle, FilterDefinition<TDocument>, TDocument, ReplaceOptions, CancellationToken)
Replaces a single document.
Task<ReplaceOneResult> ReplaceOneAsync(IClientSessionHandle session, FilterDefinition<TDocument> filter, TDocument replacement, ReplaceOptions options = null, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
filter
FilterDefinition<TDocument>The filter.
replacement
TDocumentThe replacement.
options
ReplaceOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<ReplaceOneResult>
The result of the replacement.
ReplaceOneAsync(IClientSessionHandle, FilterDefinition<TDocument>, TDocument, UpdateOptions, CancellationToken)
Replaces a single document.
[Obsolete("Use the overload that takes a ReplaceOptions instead of an UpdateOptions.")]
Task<ReplaceOneResult> ReplaceOneAsync(IClientSessionHandle session, FilterDefinition<TDocument> filter, TDocument replacement, UpdateOptions options, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
filter
FilterDefinition<TDocument>The filter.
replacement
TDocumentThe replacement.
options
UpdateOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<ReplaceOneResult>
The result of the replacement.
UpdateMany(FilterDefinition<TDocument>, UpdateDefinition<TDocument>, UpdateOptions, CancellationToken)
Updates many documents.
UpdateResult UpdateMany(FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default)
Parameters
filter
FilterDefinition<TDocument>The filter.
update
UpdateDefinition<TDocument>The update.
options
UpdateOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- UpdateResult
The result of the update operation.
UpdateMany(IClientSessionHandle, FilterDefinition<TDocument>, UpdateDefinition<TDocument>, UpdateOptions, CancellationToken)
Updates many documents.
UpdateResult UpdateMany(IClientSessionHandle session, FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
filter
FilterDefinition<TDocument>The filter.
update
UpdateDefinition<TDocument>The update.
options
UpdateOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- UpdateResult
The result of the update operation.
UpdateManyAsync(FilterDefinition<TDocument>, UpdateDefinition<TDocument>, UpdateOptions, CancellationToken)
Updates many documents.
Task<UpdateResult> UpdateManyAsync(FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default)
Parameters
filter
FilterDefinition<TDocument>The filter.
update
UpdateDefinition<TDocument>The update.
options
UpdateOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<UpdateResult>
The result of the update operation.
UpdateManyAsync(IClientSessionHandle, FilterDefinition<TDocument>, UpdateDefinition<TDocument>, UpdateOptions, CancellationToken)
Updates many documents.
Task<UpdateResult> UpdateManyAsync(IClientSessionHandle session, FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
filter
FilterDefinition<TDocument>The filter.
update
UpdateDefinition<TDocument>The update.
options
UpdateOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<UpdateResult>
The result of the update operation.
UpdateOne(FilterDefinition<TDocument>, UpdateDefinition<TDocument>, UpdateOptions, CancellationToken)
Updates a single document.
UpdateResult UpdateOne(FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default)
Parameters
filter
FilterDefinition<TDocument>The filter.
update
UpdateDefinition<TDocument>The update.
options
UpdateOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- UpdateResult
The result of the update operation.
UpdateOne(IClientSessionHandle, FilterDefinition<TDocument>, UpdateDefinition<TDocument>, UpdateOptions, CancellationToken)
Updates a single document.
UpdateResult UpdateOne(IClientSessionHandle session, FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
filter
FilterDefinition<TDocument>The filter.
update
UpdateDefinition<TDocument>The update.
options
UpdateOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- UpdateResult
The result of the update operation.
UpdateOneAsync(FilterDefinition<TDocument>, UpdateDefinition<TDocument>, UpdateOptions, CancellationToken)
Updates a single document.
Task<UpdateResult> UpdateOneAsync(FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default)
Parameters
filter
FilterDefinition<TDocument>The filter.
update
UpdateDefinition<TDocument>The update.
options
UpdateOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<UpdateResult>
The result of the update operation.
UpdateOneAsync(IClientSessionHandle, FilterDefinition<TDocument>, UpdateDefinition<TDocument>, UpdateOptions, CancellationToken)
Updates a single document.
Task<UpdateResult> UpdateOneAsync(IClientSessionHandle session, FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
filter
FilterDefinition<TDocument>The filter.
update
UpdateDefinition<TDocument>The update.
options
UpdateOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<UpdateResult>
The result of the update operation.
WatchAsync<TResult>(IClientSessionHandle, PipelineDefinition<ChangeStreamDocument<TDocument>, TResult>, ChangeStreamOptions, CancellationToken)
Watches changes on the collection.
Task<IChangeStreamCursor<TResult>> WatchAsync<TResult>(IClientSessionHandle session, PipelineDefinition<ChangeStreamDocument<TDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
pipeline
PipelineDefinition<ChangeStreamDocument<TDocument>, 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<TDocument>, TResult>, ChangeStreamOptions, CancellationToken)
Watches changes on the collection.
Task<IChangeStreamCursor<TResult>> WatchAsync<TResult>(PipelineDefinition<ChangeStreamDocument<TDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default)
Parameters
pipeline
PipelineDefinition<ChangeStreamDocument<TDocument>, 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<TDocument>, TResult>, ChangeStreamOptions, CancellationToken)
Watches changes on the collection.
IChangeStreamCursor<TResult> Watch<TResult>(IClientSessionHandle session, PipelineDefinition<ChangeStreamDocument<TDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
pipeline
PipelineDefinition<ChangeStreamDocument<TDocument>, 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<TDocument>, TResult>, ChangeStreamOptions, CancellationToken)
Watches changes on the collection.
IChangeStreamCursor<TResult> Watch<TResult>(PipelineDefinition<ChangeStreamDocument<TDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default)
Parameters
pipeline
PipelineDefinition<ChangeStreamDocument<TDocument>, 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 IMongoCollection instance with a different read concern setting.
IMongoCollection<TDocument> WithReadConcern(ReadConcern readConcern)
Parameters
readConcern
ReadConcernThe read concern.
Returns
- IMongoCollection<TDocument>
A new IMongoCollection instance with a different read concern setting.
WithReadPreference(ReadPreference)
Returns a new IMongoCollection instance with a different read preference setting.
IMongoCollection<TDocument> WithReadPreference(ReadPreference readPreference)
Parameters
readPreference
ReadPreferenceThe read preference.
Returns
- IMongoCollection<TDocument>
A new IMongoCollection instance with a different read preference setting.
WithWriteConcern(WriteConcern)
Returns a new IMongoCollection instance with a different write concern setting.
IMongoCollection<TDocument> WithWriteConcern(WriteConcern writeConcern)
Parameters
writeConcern
WriteConcernThe write concern.
Returns
- IMongoCollection<TDocument>
A new IMongoCollection instance with a different write concern setting.