The core difference between these two functions comes down to data retention.
uniqBy removes duplicate records (keeping only the first instance it finds), whereas groupBy reorganizes records that share a common variable into a nested {group} sub-collection so no data is lost.Here is how they compare using an officer holding two titles (Leslie Knope: President and Secretary):
1. The
uniqBy Approach (Data Loss)- Syntax:
{#affiliations | filter:'role':'Officer' | uniqBy:'participant_profileID'} - Result: Leslie Knope is a President.
- The Catch: The engine stops at the first match, meaning her "Secretary" title is completely dropped from the document.
- Pro Tip: Always place
uniqByafter your standard filters (likestatusorrole) in your function stack so the engine evaluates the correct pool of data before deleting duplicates.
2. The
groupBy Approach (Data Retention)- Syntax:
{#affiliations | filter:'role':'Officer' | groupBy:'participant_profileID'} - Result: Leslie Knope is a President and Secretary.
- How it works: This creates a
{group}sub-collection holding both rows of data. Inside the loop, you can use{group | grab:1:'participant_fullName'}to print her name exactly once, and{group | toSentence:'title'}to list all of her combined titles perfectly.