Table of Contents

Method ReplaceOne

Namespace
MongoDB.Driver
Assembly
MongoDB.Driver.dll

ReplaceOne(FilterDefinition<TDocument>, TDocument, ReplaceOptions, CancellationToken)

Replaces a single document.

public virtual ReplaceOneResult ReplaceOne(FilterDefinition<TDocument> filter, TDocument replacement, ReplaceOptions options = null, CancellationToken cancellationToken = default)

Parameters

filter FilterDefinition<TDocument>

The filter.

replacement TDocument

The replacement.

options ReplaceOptions

The options.

cancellationToken CancellationToken

The 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.")]
public virtual ReplaceOneResult ReplaceOne(FilterDefinition<TDocument> filter, TDocument replacement, UpdateOptions options, CancellationToken cancellationToken = default)

Parameters

filter FilterDefinition<TDocument>

The filter.

replacement TDocument

The replacement.

options UpdateOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

ReplaceOneResult

The result of the replacement.

ReplaceOne(IClientSessionHandle, FilterDefinition<TDocument>, TDocument, ReplaceOptions, CancellationToken)

Replaces a single document.

public virtual ReplaceOneResult ReplaceOne(IClientSessionHandle session, FilterDefinition<TDocument> filter, TDocument replacement, ReplaceOptions options = null, CancellationToken cancellationToken = default)

Parameters

session IClientSessionHandle

The session.

filter FilterDefinition<TDocument>

The filter.

replacement TDocument

The replacement.

options ReplaceOptions

The options.

cancellationToken CancellationToken

The 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.")]
public virtual ReplaceOneResult ReplaceOne(IClientSessionHandle session, FilterDefinition<TDocument> filter, TDocument replacement, UpdateOptions options, CancellationToken cancellationToken = default)

Parameters

session IClientSessionHandle

The session.

filter FilterDefinition<TDocument>

The filter.

replacement TDocument

The replacement.

options UpdateOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

ReplaceOneResult

The result of the replacement.