No suitable servers found using mongoc connection to DataBase

48 views (last 30 days)
I get an error when trying to start a connection to my database in MongoDB. I am using the code from the documentation:
server = "myIP";
port = 27017;
dbname = "myDBName";
conn = mongoc(server,port,dbname,UserName="user",Password="Pass");
The error I get is as follows: Error using database.mongo.connection
[Mongo Driver Error]: No suitable servers found (`serverSelectionTryOnce` set): [connection timeout
calling ismaster on 'myIP:27017'].
Error in mongoc (line 52)
conn = database.mongo.connection(varargin{:});
Error in mongodb (line 4)
conn = mongoc(server,port,dbname);
I have already verified the connection in the MongoDB shell, I also tried to connect through Compass and in both cases I can connect with my credentials. I turned off the firewall and the error still appears, I hope someone can help me.

Answers (1)

Piyush Dubey
Piyush Dubey on 30 May 2023
Hi Gerado,
[Mongo Driver Error] implicates the error is thrown by MongoDB and later sent towards MATLAB. The following documentation will help you troubleshoot different errors in MongoDB and the Database Toolbox Interface:
These will help you figure out the best practices to use the functionalities provided by the Toolbox to connect to MongoDB data base.
Additionally, this link should be helpful to resolve selection timeout errors in MongoDB:
Hope this helps!

Products


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!