I created a new project using a Fastendpoints web app template in Visual Studio 2022. It is a .net core 8.0 app that comes with an embedded notification service using a mongodb data store. I created a MongoDB account and have a database created in the cloud. I can successfully access my database via the mongodb web UI. I copied the connection string from the mongo dev portal and placed it in the app but I am unable to successfully run the app now. The mongodb WILL NOT connect successfully to my mongo database and that is blocking my ability run the app.
I installed mongodb-atlas locally and then attempted to create a local database only to have it tell me that local mongodb-atlas is not compatible with Windows OS. The initasync() call in program.cs seems to be inserting a port address into my connection string as though I'm connecting to localhost even though on Windows mongodb will not host. Here is a sample of what I am attempting, of course my username/pw removed:
await DB.InitAsync(myDbName, "mongodb://<MyUserName>:<MyPassword>@olaxxwh.mongodb.net/?authSource=admin");
My call to this gives me the following error:
System.ArgumentException: 'mongodb://<MyUserName>:<MyPassword>@olaxxwh.mongodb.net/?authSource=admin:27017'
is not a valid end point. (Parameter 'value')'
Notice the :27017 added into the connection string by the init function. I have also tried the mongodb+srv as well as mongodb but it makes no difference.
I have been battling this for 2 days. I do not understand why this is so freaking complicated. What is the magic to get initasync() using MongoDB.Entities to work??
I figured out the solution. There is an overload on
DB.InitAsync()that accepts aDbNameandMongoClientSettingsvalue. If you have a MongoDB-Atlas cloud database, pull the connection string from the MongoDB dev portal, insert your user/pw where specified, then do the following in your Fastendpointsprogram.csfile it will work!Enjoy!