I am currently trying to connect an app to the MongoDB Driver connection through Node.js, but I have had some errors in the code.
First, the error was pointing that the use of “URL=mongodb+srv://” was not valid and I should instead use just “URL=mongodb://”. When I corrected as suggested by the console I started to get this error
finstearchcluster1.gmhq7qx.mongodb.net is an SRV record, so you need to ensure your connection string in Mongoose is something like mongodb+srv://<user>:<pass>@finstearchcluster1.gmhq7qx.mongodb.net/.
The error you likely got is because you tried to append a port (27017) to the connection string when connecting using SRV.
mongodb+srv://CristianBarria:<password>@finstearchcluster1.gmhq7qx.mongodb.net/ would be correct. Does this work when you connect via the mongosh shell? Have you configured the appropriate IP Access List to ensure you can connect to the cluster?
with the new URL I am receiving the following error:
D:\..\server\node_modules\muri\lib\index.js:28
throw new Error('Invalid mongodb uri "' + str + '". Must begin with "mongodb://"');
^
Error: Invalid mongodb uri mongodb+srv://CristianBarria:BVyQIGhLHyVgRlfg@finstearchcluster1.gmhq7qx.mongodb.net/.". Must begin with "mongodb://"
at muri (D:\MERN Dashboard\server\node_modules\muri\lib\index.js:28:11)
at Connection.openUri (D:\MERN Dashboard\server\node_modules\mongoose\lib\connection.js:766:18)
at Mongoose.connect (D:\MERN Dashboard\server\node_modules\mongoose\lib\index.js:262:17)
at file:///D:/MERN%20Dashboard/server/index.js:24:10
at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
Emitted 'error' event on NativeConnection instance at:
at Connection.error (D:\MERN Dashboard\server\node_modules\mongoose\lib\connection.js:673:8)
at Connection.openUri (D:\MERN Dashboard\server\node_modules\mongoose\lib\connection.js:775:10)
at Mongoose.connect (D:\MERN Dashboard\server\node_modules\mongoose\lib\index.js:262:17)
at file:///D:/MERN%20Dashboard/server/index.js:24:10
at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
Node.js v19.9.0
I have set the IP access list prior to the connection and even set up to public sharing for this try out. I haven´t look mongosh shell yet, but I´ll try it now