Connect Async with Mongodb

Hello guys im New in Unity. Im trying to do a Highscore acene, getting datas from a Database. Right now im testing with localhost with a simples datas:

Collection User: {
“Name”: “Blá blá”,
“Age”: 30,
“score”: 3000;
}…

when I play in the game, it takes a long time to start the scene, due to the process of connecting to the pack and making the query. I would like to know if there is any way to create asynchronous actions, I come from Nodejs and there we are accustomed to this: D

Thanks

Thats my code

void Start()
{
var client = new MongoClient(connectionString);
var server = client.GetServer();
var database = server.GetDatabase(“Discord”);
var playercollection = database.GetCollection(“users”);
Debug.Log(“Conexao Realizada com Sucesso”);

foreach (var document in playercollection.FindAll())
{
Debug.Log(“4. SELECT ALL DOCS: \n” + document);
}
}`

Maybe this is not the answer you were looking for but, making direct connections with a database from a game client is asking for trouble. Anyone with a basic understanding of C# decompilation would be able get the connection coordinates to your database and mess with it to their heart’s content. (such as spamming it with bogus scores and such)

If you want to post high scores to a database you need a bit more security than that. At least you need a bit of server side logic that allows you to recognize an actually logged-in user from anyone else. The same logic then would be responsible to talk to the database. This way the client doesn’t contain any critical information on how to connect to the DB. Instead you would just POST the data to a web server, which would run such logic.

The best approach would be to run a multiplayer authoritative server, so that it can validate high scores too, not just users.