I want when one field is updated so then in the same schema there is an array who value should also be updated?

{
    "customer": "62f75f6204a24bb48edae723",
    "product": "62cd46a3b325452b3efc6dd3",
    "downPayment": 140,
    "planOfInstallment": 12,
    "moneyRequiredToPay": 629,
    "contractInitiated": false,
    "contractStatus": "Normal",
    "moneyRecieved": 0,
    "investor": [
        {
            "investorDetail": "62f7542289326e783ae7feba",
            "money": 200,
"moneyRecived": 10,
"totalEarning": 250,
"monthlyEarning: 10,
            "_id": "630e87abf5c87d202c27a2f8"
        },
        {
            "investorDetail": "62f7542289326e783ae7feba",
            "money": 170,
"moneyRecived": 8,
"totalEarning": 210,
"monthlyEarning: 8,
            "_id": "630e87abf5c87d202c27a2f9"
        }
    ],
    "createdDate": "2022-08-30T21:55:18.917Z",
    "_id": "630e87abf5c87d202c27a2f7",
    "paymentschedule": [
        {
            "monthName": "September",
            "dateToPay": "2022-09-25T21:00:00.000Z",
            "paid": false,
            "payment": 52.416666666666664,
            "paymentRecieveDate": null,
            "_id": "630e87abf5c87d202c27a2fa"
        },
        {
            "monthName": "October",
            "dateToPay": "2022-10-25T21:00:00.000Z",
            "paid": false,
            "payment": 52.416666666666664,
            "paymentRecieveDate": null,
            "_id": "630e87abf5c87d202c27a2fb"
        },
        {
            "monthName": "November",
            "dateToPay": "2022-11-25T21:00:00.000Z",
            "paid": false,
            "payment": 52.416666666666664,
            "paymentRecieveDate": null,
            "_id": "630e87abf5c87d202c27a2fc"
        },
        {
            "monthName": "December",
            "dateToPay": "2022-12-25T21:00:00.000Z",
            "paid": false,
            "payment": 52.416666666666664,
            "paymentRecieveDate": null,
            "_id": "630e87abf5c87d202c27a2fd"
        },
        {
            "monthName": "January",
            "dateToPay": "2023-01-25T21:00:00.000Z",
            "paid": false,
            "payment": 52.416666666666664,
            "paymentRecieveDate": null,
            "_id": "630e87abf5c87d202c27a2fe"
        },
        {
            "monthName": "February",
            "dateToPay": "2023-02-25T21:00:00.000Z",
            "paid": false,
            "payment": 52.416666666666664,
            "paymentRecieveDate": null,
            "_id": "630e87abf5c87d202c27a2ff"
        },
        {
            "monthName": "March",
            "dateToPay": "2023-03-25T21:00:00.000Z",
            "paid": false,
            "payment": 52.416666666666664,
            "paymentRecieveDate": null,
            "_id": "630e87abf5c87d202c27a300"
        },
        {
            "monthName": "April",
            "dateToPay": "2023-04-25T21:00:00.000Z",
            "paid": false,
            "payment": 52.416666666666664,
            "paymentRecieveDate": null,
            "_id": "630e87abf5c87d202c27a301"
        },
        {
            "monthName": "May",
            "dateToPay": "2023-05-25T21:00:00.000Z",
            "paid": false,
            "payment": 52.416666666666664,
            "paymentRecieveDate": null,
            "_id": "630e87abf5c87d202c27a302"
        },
        {
            "monthName": "June",
            "dateToPay": "2023-06-25T21:00:00.000Z",
            "paid": false,
            "payment": 52.416666666666664,
            "paymentRecieveDate": null,
            "_id": "630e87abf5c87d202c27a303"
        },
        {
            "monthName": "July",
            "dateToPay": "2023-07-25T21:00:00.000Z",
            "paid": false,
            "payment": 52.416666666666664,
            "paymentRecieveDate": null,
            "_id": "630e87abf5c87d202c27a304"
        },
        {
            "monthName": "August",
            "dateToPay": "2023-08-25T21:00:00.000Z",
            "paid": false,
            "payment": 52.416666666666664,
            "paymentRecieveDate": null,
            "_id": "630e87abf5c87d202c27a305"
        }
    ],
    "documentContract": [],
    "__v": 0,
    "id": "630e87abf5c87d202c27a2f7"
}

This is my structure for example the person pay his monthly installment of _id: 630e87abf5c87d202c27a2fa and payment paid status is true so then i need that in investor array very object has monthlyEarning is added to moneyRecieved
I need api for that?

Hello @arbabmuhammad_ramzan ,

Please correct me if my understanding of this use-case is not correct. when you get an update of "paid": true and some integer value in payment. You want to make an automatic update to some other field values in the same document?

To understand your user-case better, could you please share below details:

  1. Your expected output with respect to the document you shared above.
  2. The specific update command you used.

Regards,
Tarun