Method ReplaceOne

| MongoDB CSharp Driver API Reference (original) (raw)

Namespace

MongoDB.Driver

Assembly

MongoDB.Driver.dll

ReplaceOne(IMongoCollection, Expression<Func<TDocument, bool>>, TDocument, ReplaceOptions, CancellationToken)

Replaces a single document.

public static ReplaceOneResult ReplaceOne<TDocument>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, TDocument replacement, ReplaceOptions options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection

The collection.

filter Expression<Func<TDocument, bool>>

The filter.

replacement TDocument

The replacement.

options ReplaceOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

ReplaceOneResult

The result of the replacement.

Type Parameters

TDocument

The type of the document.

ReplaceOne(IMongoCollection, Expression<Func<TDocument, bool>>, TDocument, UpdateOptions, CancellationToken)

Replaces a single document.

[Obsolete("Use the overload that takes a ReplaceOptions instead of an UpdateOptions.")]
public static ReplaceOneResult ReplaceOne<TDocument>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, TDocument replacement, UpdateOptions options, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection

The collection.

filter Expression<Func<TDocument, bool>>

The filter.

replacement TDocument

The replacement.

options UpdateOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

ReplaceOneResult

The result of the replacement.

Type Parameters

TDocument

The type of the document.

ReplaceOne(IMongoCollection, IClientSessionHandle, Expression<Func<TDocument, bool>>, TDocument, ReplaceOptions, CancellationToken)

Replaces a single document.

public static ReplaceOneResult ReplaceOne<TDocument>(this IMongoCollection<TDocument> collection, IClientSessionHandle session, Expression<Func<TDocument, bool>> filter, TDocument replacement, ReplaceOptions options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection

The collection.

session IClientSessionHandle

The session.

filter Expression<Func<TDocument, bool>>

The filter.

replacement TDocument

The replacement.

options ReplaceOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

ReplaceOneResult

The result of the replacement.

Type Parameters

TDocument

The type of the document.

ReplaceOne(IMongoCollection, IClientSessionHandle, Expression<Func<TDocument, bool>>, TDocument, UpdateOptions, CancellationToken)

Replaces a single document.

[Obsolete("Use the overload that takes a ReplaceOptions instead of an UpdateOptions.")]
public static ReplaceOneResult ReplaceOne<TDocument>(this IMongoCollection<TDocument> collection, IClientSessionHandle session, Expression<Func<TDocument, bool>> filter, TDocument replacement, UpdateOptions options, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection

The collection.

session IClientSessionHandle

The session.

filter Expression<Func<TDocument, bool>>

The filter.

replacement TDocument

The replacement.

options UpdateOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

ReplaceOneResult

The result of the replacement.

Type Parameters

TDocument

The type of the document.