I have two separate pipelines which output the same answer. I'm trying to understand why you would use $size in the projection stage. I don't quite understand what the $size operator is doing in this pipeline.
[
{
'$project': {
'title': {
$size: {
'$split': [
'$title', ' '
]
}
}
}
}, {
'$match': {
'title': {
'$eq': 1
}
}
}, {
'$count': 'title'
}
]
I rewrote the pipeline to use $size in the $match stage instead and the output is the same. Is there some algorithmic penalty on either of these?
[
{
'$project': {
'title': {
'$split': [
'$title', ' '
]
}
}
}, {
'$match': {
'title': {
'$size': 1
}
}
}, {
'$count': 'title'
}
]