How to create custom query find data with external input hashmap

I have 2 database to store data: 1 for user management store profile , user authentication, … ( mariadb ) , 1 for device data management ( health data , monitoring data , … get from sensors , watches ). We have 3 role in our system: admin , doctor , patient.

Our scenario: doctor request all data from patients that followed by doctor and all data will be showed on website. Device data and user are map with username (device data just map with username and dont have fullname field).

My issue is: User profile is queried from mariadb by doctor and store in hashmap (key: username , value: fullname), Device data is queried from mongodb by username. It include prescription and health data. When user input name or fullname , we will create a aggregation query that generate temp column for fullname field and fullname will be get from hashmap by username. When we use $username in hashmap, it will return null and not understand $username that have to ref value which cursor current present.

User profile data:

{
"974265114": {
    "fullAvatarPath": null,
    "id": 69,
    "username": "974265114",
    "firstName": "Dad",
    "middleName": "",
    "lastName": "My",
    "nickName": "",
    "gender": 1,
    "birthday": -220924800000,
    "subscription": "standard",
    "timeZone": "Asia/Ho_Chi_Minh",
    "languageCode": "vi",
    "avatar": "/static/974265114.jpeg?t=1667267006042",
    "phonePrefix": "+84",
    "phoneNumber": "974265114",
    "homePhone": "",
    "province": null,
    "district": null,
    "ward": null,
    "address": "Thôn Hiệp Phổ Tây; Xã Hành Trung; Huyện Nghĩa Hành; Tỉnh Quảng Ngãi",
    "hasPatientProfile": true,
    "hasDoctorProfile": false,
    "hasPlayerProfile": false,
    "hasCoachProfile": false,
    "hasUpdateMedical": false,
    "firstTimeSetup": "100000",
    "latestDeviceConnected": 1667350140000,
    "fullPhoneNumber": "+84974265114"
  },
  "hoanbinh142001@gmail.com": {
    "fullAvatarPath": null,
    "id": 79,
    "username": "hoanbinh142001@gmail.com",
    "firstName": "Bình",
    "middleName": "An",
    "lastName": "Hồ",
    "nickName": "",
    "gender": 1,
    "birthday": 986083200000,
    "subscription": "standard",
    "timeZone": "Asia/Ho_Chi_Minh",
    "languageCode": "vi",
    "avatar": "",
    "phonePrefix": "+84",
    "phoneNumber": "981133890",
    "homePhone": "",
    "province": null,
    "district": null,
    "ward": null,
    "address": "Ký túc xá khu B; Phường Linh Trung; Thành phố Thủ Đức; Thành phố Hồ Chí Minh",
    "hasPatientProfile": true,
    "hasDoctorProfile": false,
    "hasPlayerProfile": false,
    "hasCoachProfile": false,
    "hasUpdateMedical": false,
    "firstTimeSetup": "100000",
    "latestDeviceConnected": 1673323040000,
    "fullPhoneNumber": "+84981133890"
  }
}

How can we can achieve that ? Thanks all.