Hi peoples!
I’ve been traversing through Google & Stack Overlow but couldn’t find a solution that works for me - I’m sure it’s a relatively simple thing i’m missing but can’t quite understand where / what’s going wrong (it doesn’t help the troubleshooting that there’s no particular error I can follow)
I’m currently working with a mongodb & attempting to update a nested document, e.g.:
{'EventName': {'UFC London: Volkov v Aspinall': {'Fight1': {'FightMethod': '',
'FightRound': '',
'FightWinner': '',
'FighterCashValue1': '1420',
'FighterCashValue2': '580',
'FighterName1': 'Sergei '
'Pavlovich',
'FighterName2': 'Shamil '
'Abdurakhimov',
'FighterOdds1': '1/3',
'FighterOdds2': '9/4'}
I’m slightly confused how I would access an existing document, like so above - and update the FightMethod, FightRound & FightWinner My current code looks like below:
def mongo_update_fight_results(EventName, i):
FightCollection = get_fight_event_collection()
EventDataQuery = {"EventName" : {f'{EventName}' : f'Fight{i}'}}
UpdateData = { "$set" : {f"EventName.{EventName}.Fight{i}.FightWinner" : 'Sergei Pavlovich'}}
DocsUpdated = FightCollection.update_one(EventDataQuery, UpdateData)
print(DocsUpdated.modified_count, "docs updated")
print(FightCollection.find_one({},{"EventName" : {f'{EventName}' : f'Fight{i}'}}))
However, I get 0 docs updated
…Any tips on how I access & update FightMethod, FightWinner & FightRound from the above document structure?