MongoDB C++ Driver mongocxx-3.6.7
Public Member Functions | List of all members
mongocxx::model::replace_one Class Reference

Class representing a MongoDB update operation that replaces a single document. More...

#include <replace_one.hpp>

Public Member Functions

 replace_one (bsoncxx::document::view_or_value filter, bsoncxx::document::view_or_value replacement)
 Constructs an update operation that will replace a single document matching the filter. More...
 
const bsoncxx::document::view_or_valuefilter () const
 Gets the filter for replacement. More...
 
const bsoncxx::document::view_or_valuereplacement () const
 Gets the replacement document. More...
 
replace_onecollation (bsoncxx::document::view_or_value collation)
 Sets the collation for this replacement operation. More...
 
const stdx::optional< bsoncxx::document::view_or_value > & collation () const
 Gets the collation option for this replacement operation. More...
 
replace_oneupsert (bool upsert)
 Sets the upsert option. More...
 
const stdx::optional< bool > & upsert () const
 Gets the current value of the upsert option. More...
 
replace_onehint (class hint index_hint)
 Sets the index to use for this operation. More...
 
const stdx::optional< class hint > & hint () const
 Gets the current hint. More...
 

Detailed Description

Class representing a MongoDB update operation that replaces a single document.

Constructor & Destructor Documentation

◆ replace_one()

mongocxx::model::replace_one::replace_one ( bsoncxx::document::view_or_value  filter,
bsoncxx::document::view_or_value  replacement 
)

Constructs an update operation that will replace a single document matching the filter.

Parameters
filterDocument representing the criteria for replacement.
replacementDocument that will serve as the replacement.

Member Function Documentation

◆ collation() [1/2]

const stdx::optional< bsoncxx::document::view_or_value > & mongocxx::model::replace_one::collation ( ) const

Gets the collation option for this replacement operation.

Returns
The optional value of the collation option.
See also
https://docs.mongodb.com/master/reference/collation/

◆ collation() [2/2]

replace_one & mongocxx::model::replace_one::collation ( bsoncxx::document::view_or_value  collation)

Sets the collation for this replacement operation.

Parameters
collationThe new collation.
See also
https://docs.mongodb.com/master/reference/collation/

◆ filter()

const bsoncxx::document::view_or_value & mongocxx::model::replace_one::filter ( ) const

Gets the filter for replacement.

Returns
The filter to be used for the replacement operation.

◆ hint() [1/2]

const stdx::optional< class hint > & mongocxx::model::replace_one::hint ( ) const

Gets the current hint.

Returns
The current hint, if one is set.

◆ hint() [2/2]

replace_one & mongocxx::model::replace_one::hint ( class hint  index_hint)

Sets the index to use for this operation.

Note
if the server already has a cached shape for this query, it may ignore a hint.
Parameters
index_hintObject representing the index to use.
Returns
A reference to the object on which this member function is being called. This facilitates method chaining.

◆ replacement()

const bsoncxx::document::view_or_value & mongocxx::model::replace_one::replacement ( ) const

Gets the replacement document.

Returns
The document that will replace the original selected document.

◆ upsert() [1/2]

const stdx::optional< bool > & mongocxx::model::replace_one::upsert ( ) const

Gets the current value of the upsert option.

Returns
The optional value of the upsert option.

◆ upsert() [2/2]

replace_one & mongocxx::model::replace_one::upsert ( bool  upsert)

Sets the upsert option.

When upsert is true, this operation will insert the replacement document as a new document if no existing documents match the filter. When upsert is false, the replacement operation does nothing if there are no matching documents. By default, upsert is false.

Parameters
upsertIf set to true, creates a new document when no document matches the query criteria. The server side default is false, which does not insert a new document if a match is not found.

The documentation for this class was generated from the following file: