0

I am having an issue creating a router that updates a boolean false value to true in my mongodb. All of this is activated by a button on my front end.

    @router.post("/started", response_description="start fight")
    async def update_started(request: Request, started: bool):
        start = await request.app.mongodb["matches"].update_one({"$set": {"started": True}})
        return start

    
    #@router.put("/update", response_description="start fight")
    #async def update_started(started: bool, request: Request):
     #   if started == False:
       #     started = request.app.database["matches"].update_one(
         #       {"started": False}, {"$set": True}
        #    )

I've tried many variations of this and am getting a 500 http error

M.O.
  • 1,712
  • 1
  • 6
  • 18
Brunyan
  • 1
  • 1
  • This is my frontend call startFight = (e) => { let data = { started: this.state.started, } axios.post(ip + 'match/started/') .then(response => { window.location.href = ip.replace(":8000", ":3000") }) .catch(err => { console.log(err); }); } – Brunyan Jan 18 '23 at 21:47
  • What error message do you get in the Python console? – M.O. Jan 18 '23 at 22:35
  • Please provide enough code so others can better understand or reproduce the problem. – Community Jan 20 '23 at 22:51

1 Answers1

0

update_one() takes two parameters; a filter and an update. You've missed off the filter and passed the update to the filter parameter.

This will be logged as an exception somewhere; you should try and find out where the console output goes otherwise tracking these issues down will be hard.

Belly Buster
  • 8,224
  • 2
  • 7
  • 20