Database

[{"key":"hello "},{"key":"world"},{"key":"test "}]

Query

db.collection.update({},[{"$set":{"key":{"$trim":{"input":"$key"}}}}],{"multi":true})

Result