The strings that you have saved through the schema are accurately trimmed with the help of the 'trim' parameter.
If you add trim to a field in your schema, then trying to save texts with spaces like " qwerty", or "goat ", or " welcome", would now be stored as "qwerty", "goat" and "welcome" in Mongo - which means that the white spaces will be excluded from both sides of the text. The syntax for trim is :
{ type: String, trim: true }