Mangrove
The C++ Object Document Mapper for MongoDB
Public Member Functions | List of all members
mangrove::comparison_expr< NvpT, U > Class Template Reference

Represents a query expression with the syntax "key: {$op: value}". More...

#include <query_builder.hpp>

+ Inheritance diagram for mangrove::comparison_expr< NvpT, U >:

Public Member Functions

constexpr comparison_expr (const NvpT &nvp, const U &field, const char *op)
 Constructs a query expression for the given key, value, and comparison type. More...
 
constexpr comparison_expr (const comparison_expr &expr, const char *op)
 Takes a comparison expression, and creates a new one with a different operator, but the same value and field. More...
 
std::string & append_name (std::string &s) const
 Appends the name of the contained field to a string.
 
void append_to_bson (bsoncxx::builder::core &builder, bool wrap=false, bool omit_name=false) const
 Appends this expression to a BSON core builder, as a key-value pair of the form "key: {$cmp: val}", where $cmp is some comparison operator. More...
 
 operator bsoncxx::document::view_or_value () const
 Converts the expression to a BSON filter for a query. More...
 

Detailed Description

template<typename NvpT, typename U>
class mangrove::comparison_expr< NvpT, U >

Represents a query expression with the syntax "key: {$op: value}".

This usually means queries that are comparisons, such as (User.age > 21). However, this also covers operators such as $exists, or any operator that has the above syntax.

Template Parameters
NvpTThe type of the name-value pair this expression uses.
UThe type of the value to compare against. This could be the same as the value type of NvpT, or the type of some other parameter, or even a query builder expression.

Constructor & Destructor Documentation

template<typename NvpT, typename U>
constexpr mangrove::comparison_expr< NvpT, U >::comparison_expr ( const NvpT &  nvp,
const U &  field,
const char *  op 
)
inline

Constructs a query expression for the given key, value, and comparison type.

Parameters
nvpA name-value pair corresponding to a key in a document
fieldThe value that the key is being compared to.
opThe type of comparison operator, such at gt (>) or ne (!=).
template<typename NvpT, typename U>
constexpr mangrove::comparison_expr< NvpT, U >::comparison_expr ( const comparison_expr< NvpT, U > &  expr,
const char *  op 
)
inline

Takes a comparison expression, and creates a new one with a different operator, but the same value and field.

This is primarily used to wrap $regex operators in $not, since $not cannot contains a $regex operator, it must directly contain the regex itself.

Parameters
exprA comparison expresison with a similar field type and value type.
opThe new operator to use.

Member Function Documentation

template<typename NvpT, typename U>
void mangrove::comparison_expr< NvpT, U >::append_to_bson ( bsoncxx::builder::core &  builder,
bool  wrap = false,
bool  omit_name = false 
) const
inline

Appends this expression to a BSON core builder, as a key-value pair of the form "key: {$cmp: val}", where $cmp is some comparison operator.

Parameters
builderA BSON core builder
wrapWhether to wrap the BSON inside a document.
omit_nameWhether to skip the name of the field. This is used primarily in not_expr and free_expr to append just the value of the expression.
template<typename NvpT, typename U>
mangrove::comparison_expr< NvpT, U >::operator bsoncxx::document::view_or_value ( ) const
inline

Converts the expression to a BSON filter for a query.

The format of the BSON is "{key: {$not: {$cmp: val}}}".


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