J
J
JRazor2016-03-31 06:43:57
Python
JRazor, 2016-03-31 06:43:57

Mongo noob question: how to change the value of a field on a specific child?

Let's say we have a structure like this:

[
    {
        "division_id": 12, 
        "players": [
            {
                "card_list": {}, 
                "first_goal": {}, 
                "player_id": 1, 
                "statistics": {}
            }, 
            {
                "card_list": {}, 
                "first_goal": {}, 
                "player_id": 2, 
                "statistics": {}
            }
        ]
    }
]

How to find a specific player by id? That is, I find this division and try to update the data via update, but I can't remember how to add them to a specific player. It's spinning right on my tongue, but something doesn't come to mind.
What not to suggest:
1) Update everything: data is taken from different places
2) Adding the player id as a key is not what I need.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel, 2016-03-31
@JRazor

db.collection.update({division_id: 12, "players.player_id": 1}, {$inc: {"players.$.card_list": 1}})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question