userver: storages::mongo::options::Projection Class Reference
Loading...
Searching...
No Matches
storages::mongo::options::Projection Class Reference

#include <userver/storages/mongo/options.hpp>

Detailed Description

Selects fields to be returned.

Note
_id field is always included by default, order might be significant
See also
https://docs.mongodb.com/manual/tutorial/project-fields-from-query-results/

Definition at line 158 of file options.hpp.

Public Member Functions

 Projection ()=default
 Creates a default projection including all fields.
 
 Projection (std::initializer_list< std::string_view > fields_to_include)
 Creates a projection including only specified fields.
 
ProjectionInclude (std::string_view field)
 Includes a field into the projection.
 
ProjectionExclude (std::string_view field)
 Excludes a field from the projection.
 
ProjectionSlice (std::string_view field, int32_t limit, int32_t skip=0)
 Setups an array slice in the projection.
 
ProjectionElemMatch (std::string_view field, const formats::bson::Document &pred)
 Matches the first element of an array satisfying a predicate.
 

Member Function Documentation

◆ ElemMatch()

Projection & storages::mongo::options::Projection::ElemMatch ( std::string_view field,
const formats::bson::Document & pred )

Matches the first element of an array satisfying a predicate.

Parameters
fieldname of the array to search
predpredicate to apply to elements
Note
Array field will be absent from the result if no elements match.
Empty document as a predicate will only match empty documents.

◆ Exclude()

Projection & storages::mongo::options::Projection::Exclude ( std::string_view field)

Excludes a field from the projection.

Warning
Projection cannot have a mix of inclusion and exclusion. Only the _id field can always be excluded.

◆ Slice()

Projection & storages::mongo::options::Projection::Slice ( std::string_view field,
int32_t limit,
int32_t skip = 0 )

Setups an array slice in the projection.

Parameters
fieldname of the array field to slice
limitthe number of items to return
skipthe following number of items
Note
skip can be negative, this corresponds to counting from the end backwards.
limit < 0, skip == 0 is equivalent to ‘limit’ = -limit, skip' = limit`.
Warning
Cannot be applied to views.

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