MongoDB C++ Driver mongocxx-3.0.3
Loading...
Searching...
No Matches
Public Member Functions | List of all members
mongocxx::model::update_one Class Reference

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

#include <update_one.hpp>

Public Member Functions

 update_one (bsoncxx::document::view_or_value filter, bsoncxx::document::view_or_value update)
 Constructs an update operation that will modify a single document matching the filter.
 
const bsoncxx::document::view_or_valuefilter () const
 Gets the filter.
 
const bsoncxx::document::view_or_valueupdate () const
 Gets the update document.
 
update_oneupsert (bool upsert)
 Sets the upsert option.
 
const stdx::optional< bool > & upsert () const
 Gets the current value of the upsert option.
 

Detailed Description

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

Constructor & Destructor Documentation

◆ update_one()

mongocxx::model::update_one::update_one ( bsoncxx::document::view_or_value  filter,
bsoncxx::document::view_or_value  update 
)

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

Parameters
filterDocument representing the criteria for applying the update.
updateDocument representing the modifications to be applied to the matching document.

Member Function Documentation

◆ filter()

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

Gets the filter.

Returns
The filter to be used for the update operation.

◆ update()

const bsoncxx::document::view_or_value & mongocxx::model::update_one::update ( ) const

Gets the update document.

Returns
The modifications to be applied as part of the update.

◆ upsert() [1/2]

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

Gets the current value of the upsert option.

Returns
The optional value of the upsert option.

◆ upsert() [2/2]

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

Sets the upsert option.

When upsert is false, if no document matches the filter, update does nothing. However, by specifying upsert as true, this operation either updates a matching document or inserts a new document using the update specification if no matching document exists. 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: