0
{
"policies": [
    {
        "fund_values": [
            {
                "percentage": 77,
                "_id": "5e240207c5f5041bd8c90e43"
            },
            {
                "percentage": 81,
                "_id": "5e2404edfe10180a249cdd2b"
            }
        ],
        "_id": "5e23f9d146608630a0bcea7e"
    },
],
"name": "myname",
"_id": "5e0894ff361c550b38f4d46f"
}

Hi. i decided to ask again even though this may look like a duplicate post. I have tried the suggested posted but they do not work.

This is what i have currently

Client.findOneAndUpdate({ '_id': req.params.client_id, 'policies._id': req.params.policy_id , 'policies.0.fund_values._id': req.params.client_fund_value_id }, 
    { 
        '$set': { 
            'policies.$.fund_values.0.percentage': req.body.percentage
        } 
    }, { new: true }, 
    function(err, client) {
        if (err) {
            res.status(500).send(err);
            return;
        }

        res.json(client);
    }
);

This may look ok but this code specifically alters the first fund value object in the array. i read that using $ won't work. so in this case what is the correct syntax?

chitgoks
  • 311
  • 2
  • 6
  • 17

0 Answers0