addFields() function
Home > @cbnsndwch/zero-contracts > addFields
addFields() function
Creates an $addFields pipeline stage for adding computed fields.
This is equivalent to MongoDB's $addFields aggregation operator. Adds new fields or replaces existing fields with computed values.
Signature:
declare function addFields(fields: Record<string, any>): SetStage;Parameters
Parameter
Type
Description
fields
Record<string, any>
Object mapping field names to computed expressions
Returns:
An $addFields stage
Example
const stage = addFields({
isOwner: { $eq: ['$role', 'owner'] },
fullName: { $concat: ['$firstName', ' ', '$lastName'] },
computedAt: new Date().toISOString()
});
// { $addFields: { isOwner: ..., fullName: ..., computedAt: ... } }How was this page?