ProjectionOperator type
Home > @cbnsndwch/zero-contracts > ProjectionOperator
ProjectionOperator type
Represents a projection operator used in database queries or data transformations.
A projection operator is an object where keys are operator names starting with a dollar sign ($), and values can be: - DocumentPath: References to fields (e.g., '$_id', '$user.name') - Arrays: For operators like $concat that take multiple arguments - Nested operators: For composed operations - Primitive values: For literal values
Common operators include: - Type conversion: $toString, $toInt, $toBool - String operations: $concat, $substr, $toLower, $toUpper - Custom operators: $hexToBase64Url - Logical operators: $eq, $ne, $and, $or
Signature:
type ProjectionOperator = {
[operator: `$${string}`]:
| DocumentPath
| ProjectionOperator
| Array<DocumentPath | ProjectionOperator | string | number | boolean>
| string
| number
| boolean;
};References: DocumentPath, ProjectionOperator
Example
// Simple field reference
const simpleOp: ProjectionOperator = {
$toString: '$_id'
};
// String concatenation
const concatOp: ProjectionOperator = {
$concat: ['$firstName', ' ', '$lastName']
};
// Nested operators
const nestedOp: ProjectionOperator = {
$concat: [{ $hexToBase64Url: '$_id' }, '_', '$members.id']
};How was this page?