0

I have checked in the links below for information on this question before posting https://www.youtube.com/watch?v=XRXjJRJ03_A Update field in exact element array in MongoDB

My Data

{
    '_id': ObjectId('608b07c8f2cd2853333e1892'),
    'DISNAME': '92bricks#4696',
    'AVATAR': 'https://cdn.discordapp.com/avatars/306429381948211210/bcbd8bffe41170afedf18bebe030c675.webp?size=1024',
    'IGN': [{
        'Call Of Duty Mobile': 'BRICKS'
    }],
    'GAMES': ['Call Of Duty Mobile'],
    'TEAMS': ['mcdonalds'],
    'TITLES': ['PCG'],
    'RANKED': [{
        '1V1': [0, 0, 0]
    }, {
        '2V2': [0, 0, 0]
    }, {
        '3V3': [0, 0, 0]
    }, {
        '4V4': [0, 0, 0]
    }, {
        '5V5': [0, 0, 0]
    }],
    'NORMAL': [{
        '1V1': [0, 0, 0]
    }, {
        '2V2': [0, 0, 0]
    }, {
        '3V3': [0, 0, 0]
    }, {
        '4V4': [0, 0, 0]
    }, {
        '5V5': [0, 0, 0]
    }],
    'TOURNAMENT_WINS': 0,
    'TIMESTAMP': 'Thu Apr 29 12:21:53 2021'
}

I'm trying to update / increment NORMAL.$.1V1.1 (The middle item in the array of 0's)

I've tried {'$set': {'NORMAL.$.1V1.1': 1}} but it keeps throwing error full error: {'index': 0, 'code': 2, 'errmsg': 'The positional operator did not find the match needed from the query.'}

The video that I linked above says to build the logic in the syntax I posted above ({'$set': {'NORMAL.$.1V1.1': 1}}). Any ideas?

Belly Buster
  • 8,224
  • 2
  • 7
  • 20
Chris Simmons
  • 249
  • 2
  • 7
  • 19

2 Answers2

0

If you know it's that item you want to update specifically, then the update is:

db.coll.update_one({}, {'$set': {'NORMAL.0.1V1.1': 1}})
Belly Buster
  • 8,224
  • 2
  • 7
  • 20
0

Found the answer to with some help from Belly Buster.

new_value = {"$inc": {'NORMAL.$[type].' + game_type.upper() + '.1': 1}}
filter_query = [{'type.' + game_type.upper(): current_score}]

This will make it dynamic based on existing data.

Chris Simmons
  • 249
  • 2
  • 7
  • 19