userver: storages::mongo::options::Projection Class Reference
No Matches
storages::mongo::options::Projection Class Reference

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

Detailed Description

Selects fields to be returned.

_id field is always included by default, order might be significant
See also

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.

fieldname of the array to search
predpredicate to apply to elements
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.

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.

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

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