Documentation ¶
Overview ¶
Package operators provides aggregation operators. Operators are used in aggregation stages to filter and model data. This package contains all operators apart from the accumulation operators, which are stored and described in accumulators package.
Accumulators that can be used outside of accumulation with different behaviour (like `$sum`), should be stored in both operators and accumulators packages.
Package operators provides aggregation operators.
Index ¶
Constants ¶
const ( // ErrArgsInvalidLen indicates that operator have invalid amount of arguments. ErrArgsInvalidLen operatorErrorCode // ErrTooManyFields indicates that operator field specifes more than one operators. ErrTooManyFields // ErrNotImplemented indicates that given operator is not implemented yet. ErrNotImplemented // ErrInvalidExpression indicates that given operator does not exist. ErrInvalidExpression // ErrInvalidNestedExpression indicates that operator inside the target operator does not exist. ErrInvalidNestedExpression )
Variables ¶
var Operators = map[string]newOperatorFunc{
"$sum": newSum,
"$type": newType,
}
Operators maps all standard aggregation operators.
Functions ¶
func IsOperator ¶
IsOperator returns true if provided document should be treated as operator document.
Types ¶
type Operator ¶
type Operator interface { // Process document and returns the result of applying operator. Process(in *types.Document) (any, error) }
Operator is a common interface for standard aggregation operators.
func NewExpr ¶
NewExpr validates and creates $expr operator which allows usage of aggregation expression from query and $match aggregation stage. $expr operator is a top level operator and cannot be used from nested expression.
It returns CommandError for invalid value of $expr operator.
func NewOperator ¶
NewOperator returns operator from provided document. The document should look like: `{<$operator>: <operator-value>}`.
Before calling NewOperator on document it's recommended to validate document before by using IsOperator on it.
type OperatorError ¶
type OperatorError struct {
// contains filtered or unexported fields
}
OperatorError is used for reporting operator errors.
func (OperatorError) Code ¶
func (opErr OperatorError) Code() operatorErrorCode
Code returns operatorError code.
func (OperatorError) Error ¶
func (opErr OperatorError) Error() string
Error implements error interface.
func (OperatorError) Name ¶
func (opErr OperatorError) Name() string
Name returns the name of the operator (e.g. $sum) that produced an error.
Directories ¶
Path | Synopsis |
---|---|
Package accumulators provides aggregation accumulator operators.
|
Package accumulators provides aggregation accumulator operators. |