pymongo ServerSelectionTimeoutError with a valid mongo URL - mongodb

I've been having issues while connecting to a MongoDB database using pymongo.
I use valid URLs, since my colleagues are using the same and it works fine for them, but I keep getting ServerSelectionTimeoutError.
The databases are hosted on MongoAtlas, do you have any idea about what the issue is?

Any issue with a ServerSelectionTimeoutError is a connection issue with the targeted database.
It turns out MongoAtlas has a nice documentation about those: https://docs.atlas.mongodb.com/troubleshoot-connection/
In my case, the issue was that I was on a network with a firewall that closed the needed 27017 port, a simple change of network did the trick.

Related

Connect to Database directly via Mongo Compass

Via shell, I can directly connect to mongo database with this string
mongo --ssl host1,host2:port/MyDataBase...
And I land directly on the MyDataBase.
Is there a similar way to do it in Compass? I get connected to whole server and I can see all the other databases. I just want to connect to MyDataBase.
I am using the lattest version of Compass, so it may differ from your current version.
It is important the you are in the network of the server, or use a VPN connection, otherwise, it does not work.
Step 1
Step 2
Please,let me know if that works!

Error : No unix socket support on windows connecting mongodb

I'm using robomongo tool to access mongodb. When I connect into my db then
Show error details
How to fix it?
I had the same issue and was able to fix it by removing the full url (for example: mongodb://myuser:mypassword#mongodb-test.mydomain.com/my_database) in the connection tab and only putting in the mongodb server url: mongodb-test.mydomain.com.
Next, in the Authentication tab, I checked the Perform authentication checkbox, specified the Database, user name, password.
I also added the database in the Advanded tab just in case and I can now connect without error.
Try inserting only e.g: ds12345.mlab.com at address bar instead of full [http:// mongodb://<dbuser>:<dbpassword>#...] and create user to authenticate in mlab.com and then try connect to it. Something like this:
And then:
Whilst this answer is only partly related to the problem, I want to describe the solution in here.
I had this problem when trying to connect via Robo3T to a cluster of MongoDBs hosted on Atlas. They offer a connection string with the protocol in front (e.g. mongodb+srv://<USER>:<PASSWORD>#database-mongodb.net/admin). This was a combination of two problems:
Robo3T does not like the protocol mongodb+srv:// in the URI. You should use only the second part (after the #). Like: database-mongodb.net.
Robo3T does not like shards. At least I could not get to connect with it via that connection string. Fro what I understand, you need that protocol to connect to a shard. Since you can't use that kind of URI, you will need to connect directly to the primary shard. To do that, you need to build a new connection string with the URI of the primary shard. Like this: database-shard-00-00-vemhh.mongodb.net and provide the port to Robo3T. Also, you need to connect via SSL, if you're using MongoDB Atlas (a self-signed certificate configured directly in Robo3T worked for me).
Remove only [http://] worked for me
Get the newer version of the Robo3T client...it can import it automatically from +srv link
I was facing the same problem, but I can solve it by installing Robo 3T 1.3 and import connection details from MongoDB SRV connection string. See this:
Steps to connect remote DB from Robo 3T 1.3
Remember to replace the user in the connection string and the pass at Authentication Tab
The connection string in the picture is dummy by the way

MongoDB getting error while setting up at WAMP localhost for window

I am setting up MongoDB on localhost WAMP,
when i hit the port number http://127.0.0.1:28017 getting following error:
It looks like you are trying to access MongoDB over HTTP on the native driver port.
Please let me know how can i view database like phpmyadmin for MongoDB.
MongoDB does not offer by default a Webinterface for Administration, so you have to use additional Software. I know that Adminer also supports MongoDB.
Otherwise please read this Section in the MongoDB Docs (which are really great for learning MongoDB. I haven't tried all of them, but i think Adminer will do the Jobs. The MongoDB Shell is also great.
You can use cPanel too for this. cPanel server , because it is just another linux server.

Can not access MongoDb collections on Compose.io with Mongo Client

Since last week I can not access my mongoDb collections on Compose.io using any mongo client. Client log says it is connected to DB but when I want to list collections or view document says "Collection not found!". I till can connect with terminal and do there whatever I need.
Initially I thought it is a problem with my MacOS machine, but then I tried to connect from other computers and using different clients ( Mongo-Express, MongoHub ) still no luck.
Wondering if I'm experiencing this problem alone or other compose.io clients also do ?
Tried to grant readWrite role to my mongo user as advised here (MongoDB - admin user not authorized), this does not help either.
Contacted compose.io support, but they swear that did change anything.
Any advise appreciated.
Thank you.
I was trying to connect to slave node which fails with { [MongoError: not master and slaveOk=false] name: 'MongoError' }
. Connecting with MongoClient to primary node solves the problem.

Mongo vs Mongoid - why can 1 connect and the other not?

I have a rails-app which uses both mongoid and mongo. I use mongoid for my own models, and I use mongo because I have ruote with a ruote-mon storage.
In production however; I get
Mongo::ConnectionFailure: Failed to connect to a master node at localhost:27017
when I try to connect to the ruote storage. Even when I just do Mongo::MongoClient.new
Steps I have taken so far to try to resolve this:
I have made my mongodb an explicit master by setting master = true in /etc/mongod.conf
There are no $ENV variables set that could intervene with Mongo::MongoClient.new (double checked)
I have tried to connect using Mongo::MongoClient.new(:slave_ok => true) - same error
I have restarted my mongo database several times (w/o success).
I have checked my firewall settings and I can connect to localhost:27017 with telnet (as said, the mongoid documents can be fetched and stored w/o issue)
I am out of my wits... Any suggestions?
The reason this happened is because we were sending queries with meta operators ($query, $orderby, etc...) for the ismaster command during a connect. This command's output is used to determine whether you are connected to a primary or not and would fail because very old versions of mongodb don't support the use of meta operators.
This fix will be in version 1.8.2 of the gem but I strongly encourage anyone who is still running pre-1.8 versions of mongodb to upgrade. 2.0 is the current legacy release as of the time of this post and even 1.8 is no longer widely supported.
As jmettraux mentioned you can find more details about this on the MongoDB project Jira under Ruby-525
please look at: https://jira.mongodb.org/browse/RUBY-525
Should be fixed by the 1.8.2 mongo gem.