I went through many other posts but none of the solutions worked for me. I asked the following question in reply to someone’s post but couldn’t sort out the issue so now I am posting it as a separate topic.
So, without going into other details of my project, I have a collection containing multiple documents. In each document, there is an array named “team” and inside this array, I have objects. Each individual object contain information for a particular player like name, points, _id and isCaptain (which tells that whether this particular player is a captain of this team or not in the form of ‘true’ and ‘false’ i.e isCaptain: true means that this player is captain of this team and isCaptain: false means that this player is not a captain of this team). From the frontend, I am sending two values; id and points. Now, what I am doing is that I’m fetching/reaching out to all the players(objects) whose _id matches with the input ‘_id’ (coming from the frontend). After this, I want to check if this player is the captain of this team or not. If he is, then I want to $set the points of this player as double points by doing points 2x. And if that player is not a captain, then I just want to $set points to the input points without making it double.*
*I was able to do everything but I’m stuck on isCaptain. I want my code to be modelled in such a way that it checks the matching _id and also check that if that player is captain or not. If he is captain than double the points (points 2x) otherwise go to the other update operation. I have attached the code snippet plus the Screenshots of my documents.
Let me know if I was able to make it clear enough for you to understand. If you need more details, I can provide you with that.