In MongoDB, the $trim
aggregation pipeline operator removes whitespace from the beginning and end of a string. This includes the null character.
It can also remove any character specified. For example, you could use it to remove all hyphen characters (-
) or periods (.
) or all s
characters, etc.