Мангуст находит объект из вложенного массива ссылок

#node.js #mongoose

Вопрос:

Мне нужен массив объектов patientBill по идентификатору врача из массива performed_by_doctors. В накладной пациента я дал ссылку на служебное положение, а в Служебном положении я дал ссылку на Врача . Я дам идентификатор врача в теле, и эта приведенная ниже логика должна найти объекты patientBill, в которых вложенный массив servicemanagement, массив performed_by_doctors содержал этот идентификатор врача.

 const getPatientBillByDoctor = async () => {
    return PatientBill.find( { 'serviceManagement.performed_by_doctors._id' : mongoose.Types.ObjectId("61437fd1f79fc508ecf2336f") }).populate({
        path: 'serviceManagement patient food room',
        populate: 'serviceManagement serviceInfo performed_by_doctors',
    });
}
 

Это мой объект, который я хочу получить в результате запроса.

 {
        "serviceManagement": [
            {
                "performed_by_doctors": [
                    {
                        "servicesPrices": [
                            "61437fd1f79fc508ecf2336f",
                            "61437fe9f79fc508ecf23374"
                        ],
                        "created_at": "Tue Sep 21 2021 18:42:15 GMT-0700 (Pacific Daylight Time)",
                        "_id": "614a98fef1fcd04e40864aaf",
                        "images": "61597ab7cb833160c0b235f2",
                        "name": "Ahmed",
                        "phone": "03076783593",
                        "gender": "male",
                        "city": "jhjgjh",
                        "education": "BSCS",
                        "consultancyFee": "1000",
                        "specialization": "613799da0367e84398b201ec",
                        "shift": "61388cb7f213853330b270f2",
                        "department": "613631d723bec3131cf19353",
                        "salary": "613a10c24bc65440f0643b42",
                        "__v": 2,
                        "updated_at": "Sun Oct 03 2021 02:41:11 GMT-0700 (Pacific Daylight Time)"
                    }
                ],
                "created_at": "Mon Oct 11 2021 04:02:17 GMT-0700 (Pacific Daylight Time)",
                "_id": "61641a59cc139b28d01ed12d",
                "serviceInfo": {
                    "doctors": [
                        "614a98fef1fcd04e40864aaf",
                        "614c4eda7aa323416cfa6aa6"
                    ],
                    "created_at": "Thu Sep 09 2021 01:39:23 GMT-0700 (Pacific Daylight Time)",
                    "_id": "6139c8e4c7af9304e4494c37",
                    "name": "operation",
                    "description": "fgeyif akfg akf ksg",
                    "__v": 1,
                    "updated_at": "Mon Sep 27 2021 03:03:38 GMT-0700 (Pacific Daylight Time)",
                    "department": "613631d723bec3131cf19353",
                    "category": "615063a3db74da7fc4137eb5",
                    "price": "50000",
                    "serviceExpenses": "467q75"
                },
                "patient": "615c3a18720956712096921b",
                "__v": 0
            }
        ],
        "created_at": "Mon Oct 11 2021 04:02:18 GMT-0700 (Pacific Daylight Time)",
        "food": [
            {
                "created_at": "Fri Sep 10 2021 06:47:47 GMT-0700 (Pacific Daylight Time)",
                "_id": "613b63513664e4589ce0e7c3",
                "name": "breakfast",
                "price": "1000",
                "foodCategory": "613b623c3664e4589ce0e7b8",
                "__v": 0,
                "updated_at": "Tue Oct 05 2021 01:11:00 GMT-0700 (Pacific Daylight Time)"
            }
        ],
        "_id": "61641a71cc139b28d01ed13a",
        "patient": {
            "images": [],
            "created_at": "Tue Oct 05 2021 04:36:35 GMT-0700 (Pacific Daylight Time)",
            "_id": "615c3a18720956712096921b",
            "name": "Leanne Graham",
            "age": "24",
            "phone": "010-692-6593 x09125",
            "gender": "Male",
            "city": "smd",
            "description": "2nd description of nurse category",
            "recentAppointment": "tuesday",
            "futureAppointment": "tuesdat",
            "__v": 11,
            "food": [
                "613b63513664e4589ce0e7c3",
                "613b633e3664e4589ce0e7c0",
                "6140c2db8b229458a4a0feef",
                "61504c16d12c675564b2ddde",
                "61504c04d12c675564b2ddd8"
            ],
            "updated_at": "Tue Oct 05 2021 12:03:24 GMT-0700 (Pacific Daylight Time)"
        },
        "totalBill": "61000",
        "status": "Done",
        "createdAt": "2021-10-11T11:05:21.602Z",
        "updatedAt": "2021-10-11T11:06:19.726Z",
        "__v": 2,
        "room": {
            "status": "Free",
            "created_at": "Tue Sep 14 2021 10:01:38 GMT-0700 (Pacific Daylight Time)",
            "_id": "6140d7a2f663ec65c82ae31e",
            "food": [
                "613b63513664e4589ce0e7c3"
            ],
            "number": "4",
            "per_day_price": "10000",
            "AC": "No",
            "roomCategory": "6140d9e5f663ec65c82ae335",
            "__v": 4,
            "updated_at": "Mon Oct 11 2021 04:07:04 GMT-0700 (Pacific Daylight Time)",
            "ward": null,
            "OccupiedDate": null
        },
        "updated_at": "Mon Oct 11 2021 04:06:19 GMT-0700 (Pacific Daylight Time)"
    },