operators

package
v0.0.0-...-bb56650 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 20, 2024 License: MIT Imports: 11 Imported by: 0

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

View Source
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

View Source
var Operators = map[string]newOperatorFunc{

	"$sum":  newSum,
	"$type": newType,
}

Operators maps all standard aggregation operators.

Functions

func IsOperator

func IsOperator(doc *types.Document) bool

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

func NewExpr(exprValue *types.Document, errArgument string) (Operator, error)

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

func NewOperator(doc *types.Document) (Operator, error)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL