How to find whitespace in subdocument and trim the spaces?

Is there any way to do this: I have a requirement to identify subdocument which has whitespace (leading and/or trailing) as shown below. Once the query identifies the record, I want to trim its spaces and update the record.

Expected output: Query should return only first subdocument where name and key has whitespaces.

  1. How to identify subdocument which has whitespace?
  2. How to trim and update the identified record?

Sample:

{
  "_id": { "$oid": "60d473872dfc4cb7bca7be22" },
  "number": "103487",
  "code": "002",
  "summary": [
    {
      "name": "  AP ",
      "key": "  ",
      "modifiedDate": { "$date": "2020-11-15T00:00:00.000Z" }
    },
    {
      "name": "IND",
      "key": "ED",
      "modifiedDate": { "$date": "2020-11-16T00:00:00.000Z" }
    },
    {
      "name": "ENG",
      "key": "MD",
      "modifiedDate": { "$date": "2020-09-06T00:00:00.000Z" }
    },
    {
      "name": "AUS",
      "key": "BI",
      "modifiedDate": { "$date": "2021-04-06T00:00:00.000Z" }
    }
  ]
}