I don't know what MongoDB is, or what you were doing with all that code in the beginning. I'm trying to use reCAPTCHA v3 this on a basic upload, registration, and login forms on my website I'm building from scratch.
In this simple application, I was using MongoDB to store the data collected in the sample form. To use reCAPTCHA v3, you need to use the client-side javascript to produce a token based on the user's interaction with the page and then pass the token to your backend which verifies the token with reCAPTCHA service to determine whether or not the interaction was legitimate.