$reduce
New in form 3.4.
Applies an articulation to every component in a cluster and consolidates them into a solitary worth.
$objectToArray
New in form 3.4.4.
Changes over a record to a cluster. The arrival cluster contains a component for each field/esteem pair in the first report. Every component in the arrival cluster is an archive that contains two fields k and v:
$map
Applies an articulation to every thing in a cluster and returns an exhibit with the applied outcomes.
Example of 2 pipleline :
{
sent_to: 1,
cc: 1,
bcc: 1,
template_data: 1,
created_datetime: 1,
subject: 1,
template: 1,
group: 1,
priority: 1,
MessageId: 1,
sent_datetime: {
$cond: {
'if': {
$ifNull: [
'$sent_datetime',
'$Unspecified'
]
},
then: '$sent_datetime',
'else': ''
}
},
emailstatus: {
$switch: {
branches: [
{
'case': {
$eq: [
'$status',
1
]
},
then: 'Successful'
},
{
'case': {
$eq: [
'$status',
0
]
},
then: 'Failed'
}
],
'default': 'NA'
}
},
subject_search: {
$toLower: '$subject'
},
group_search: {
$toLower: '$group'
},
templatedata: {
$cond: {
'if': {
$and: [
{
$isArray: '$template_data'
}
]
},
then: {
$objectToArray: {
$arrayElemAt: [
'$template_data',
0
]
}
},
'else': []
}
}
}
/////////
{
subject: 1,
group: 1,
priority: 1,
MessageId: 1,
sent_datetime: 1,
emailstatus: 1,
subject_search: 1,
group_search: 1,
created_datetime: 1,
cc: 1,
bcc: 1,
sent: '$sent_to',
template: '$template_data',
templatedatastr: {
$cond: {
'if': {
$and: [
{
$isArray: '$templatedata'
}
]
},
then: {
$reduce: {
input: {
$map: {
input: '$templatedata',
as: 'templatedata',
'in': {
$concat: [
{
$convert: {
input: '$$templatedata.k',
to: 'string',
onError: 'empty',
onNull: 'empty'
}
},
': ',
{
$convert: {
input: '$$templatedata.v',
to: 'string',
onError: 'empty',
onNull: 'empty'
}
}
]
}
}
},
initialValue: '',
'in': {
$concat: [
'$$value',
'$$this',
','
]
}
}
},
'else': "NA"
}
}
}