0

I have the document below and I need to insert an object into the players arrays how to do this with mongoDB

{
        "data": {
            "createTournament": {
                "_id": "6130d9a565aa744f173a824a",
                "title": "Jogo de truco",
                "description": "",
                "status": "PENDING",
                "size": 8,
                "prizePool": 20,
                "currency": "USD",
                "type": "Battle",
                "entryFee": 1,
                "startDate": "2021-09-01",
                "endDate": "2021-09-01",
                "rounds": [{
                    "round": 1,
                    "totalMatches": 4,
                    "matches": [{
                            "match": 1,
                            "players": []
                        }
                    ]
                }]
            }
        }
    }
1

1 Answer 1

0

it will add 3 to array players that array matches has match of 1 and rounds array has round of 1

db.collection('exmaple').updateOne({},
{
      $push:{"data.createTournament.rounds.$[outer].matches.$[inner].players":"3"}
    },
    { "arrayFilters": [
      { "outer.round": 1 }, // you could change this to choose in which array must be pushed
      { "inner.match":1  } // // you could change this to choose in which array must be pushed
  ] }
)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.