DNSHostNotFound: Failed to look up service "":DNS name does not exist. try - mongodb

DNSHostNotFound: Failed to look up service "":DNS name does not exist. try 'C:\Program Files\MongoDB\Server\4.2\bin\mongo.exe --help' for more information
I am getting this error while coonecting with Sandbox to mongo shell.
PS C:\Users\hp> mongo -version
MongoDB shell version v4.2.7
git version: 51d9fe12b5d19720e72dcd7db0f2f17dd9a19212
allocator: tcmalloc
modules: enterprise
build environment:
distmod: windows-64
distarch: x86_64
target_arch: x86_64
What is the error? I am not able to understand.

DNS using Spectrum blocks srv requests to MongoDB Atlas. I had to change my DNS servers to Google's 8.8.8.8

guessing from the kind of question it seems that you were taking mongoDB university course M001. I too, was taking that course and have faced a similar problem. The solution is to remove the password part from the string or command. The following snippet will help to understand this.
Instead of the command-
mongo "mongodb+srv://sandbox-jbc3i.mongodb.net/test" --username m001-student --password m001-mongodb-basics
Enter-
mongo "mongodb+srv://sandbox-jbc3i.mongodb.net/test" --username m001-student
After this password authentication will be asked. Now here's a twist, you cannot see the password which you are typing in command prompt or powershell interface. Just type it and then press enter, and you will be connected to the mongoDB atlas. After that, you should see the prompt-
MongoDB Enterprise Sandbox-shard-0:PRIMARY>
Hope this helps.

I am writing this answer after researching on many websites and even contacted MongoDB support.
The problem is regarding the DNS server of your wifi. Kindly change your wifi or use the mobile hotspot and also whitelist the current connected IP on MongoDB, It will surely help, or Change the DNS of your wifi.

Please whitelist your ip first and then use a mobile-hotspot to connect. Modify the databaseuser (by changing its username and password) and then try to connect. It will work.

Related

Can't connect Mongo shell to Mongo Atlas M0 using mongodb+srv

I am trying to connect to my MongoDB Atlas Cloud cluster via the mongo+srv connection like so:
mongo "mongodb+srv://cluster0-mhzdc.mongodb.net/test" --username myuser
I am getting this response:
DNSHostNotFound: Failed to look up service "_mongodb._tcp.cluster0-mhzdc.mongodb.net": Undefined error: 0
try 'mongo --help' for more information
I am using the following version of Mongo client:
mongo --version
MongoDB shell version v4.0.5
git version: 3739429dd92b92d1b0ab120911a23d50bf03c412
allocator: system
modules: none
build environment:
distarch: x86_64
target_arch: x86_64
I can't find any resolution online. Any ideas what's wrong? Is this a bug in the given version of the Mongo shell client?
It looks like bug 34117, still unresolved:
https://jira.mongodb.org/browse/SERVER-34117
To work around the bug check if you have a DNS resolver active on your notebook.
On windows:
ipconfig /displayDNS
to see the current DNS resolver cache.
You might even try to erase the cache with the command:
ipconfig /flushdns
and retry.
If you are working on linux ubuntu try the command:
named -v
to check if the DNS resolver software is already installed.
If not:
sudo apt update
sudo apt install bind9 bind9utils bind9-doc bind9-host
to install the needed packages, then start the service:
sudo systemctl start bind9
and retry.
On Mac OSX, the command is:
sudo killall -HUP mDNSResponder;sudo killall mDNSResponderHelper;sudo dscacheutil -flushcache
The same happens to me, but just after i change my internet provider. Before, i could connect to mongo atlas with no problem.
I guess this happens because the DNS resolver of my internet provider could not resolve the uri to connect to mongodb atlas.
The Solution ->
Change de DNS resolver on my PC:
Open the Control Panel.
Click View network status and tasks
Click Change adapter settings on the left portion of the window.
Double-click the icon for the Internet connection you're using.
Click the Properties button.
Click and highlight Internet Protocol Version 4 (TCP/IPv4) and click Properties.
If not already selected, select the Use the following DNS server addresses option.
Enter the new DNS addresses and click OK and close out of all other windows.
I used google public dns 8.8.8.8.
After that i could connect again with my mongo shell ou compass to mongo atlas.
Hope that helps someone..
I also had this problem with Comcast Xfinity. For those running Ubuntu 18.04 or similar, I had to edit (you'll need root permissions) the /etc/dhcp/dhclient.conf file, and add to following line:
supersede domain-name-servers 8.8.8.8, 8.8.4.4;
I hope this helps somebody, took me too long to figure it out. :-)
I spent lot of time to figure the out issue. after the change DNS it worked. thanks
Used google dns servers.
8.8.8.8
8.8.4.4

How can i restrict the user in MongoDB?

I have created user with read permissions in Mongodb. I have done the same process here
but still user was not restricted with permissions.User can create the collection and insert the document but user have only read permissions.
When I opened mongo.exe, it was showing some warnings.
ongoDB shell version v4.0.0
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 4.0.0
Server has startup warnings:
2018-09-17T01:11:07.042-0400 I CONTROL [initandlisten]
**2018-09-17T01:11:07.042-0400 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-09-17T01:11:07.042-0400 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.******
2018-09-17T01:11:07.042-0400 I CONTROL [initandlisten]
---
So how can i restrict the user in MongoDB?
So, you are missing few things in configure section.
you need to activate in the mongod configuration file.
it will be located in /etc/mongod.conf if you are using Linux.
you need to change/uncomment/add this section below:
security:
authorization: "enabled"
and after that you need to restart mongod service.
in my case service name is mongod .
so i did sudo systemctl restart mongod .
and as you already having role. and authentication enabled just now.
you have to login now.
>> mongo --port <YOUR_MONGO_PORT>
> use admin
> db.auth("username","password")
it should login now.
all steps:
Create Users with needed Roles.
Enable Authetication in DB config level.
Dont forget to Restart The Database service.
Try To login. You are Good to Go.
You can look into this medium post as well here.

Mongodb not accessible on host when run via docker-compose but works via docker

I`m trying to connect to mongodb in docker container from a host ( for dev purposes solely) without any luck.
I have following docker-compose file.
version: '2.2'
services:
mongo:
image: mongo
ports:
- "27017:21017"
And when i try to connect to it i'm getting following error:
C:\Program Files\MongoDB\Server\3.4\bin>mongo
MongoDB shell version v3.4.9
connecting to: mongodb://127.0.0.1:27017
2017-10-25T03:48:53.331+0300 E QUERY [thread1] Error: network error while attempting to run command 'isMaster' on host '127.0.0.1:27017' :
connect#src/mongo/shell/mongo.js:237:13
#(connect):1:6
exception: connect failed
But if i launch it without compose directly e.g.
docker run --name my_mongox6 -d -p 27017:27017 mongo
Which should be equivalent of the docker-compose file above.
And it works perfectly fine
C:\Program Files\MongoDB\Server\3.4\bin>mongo
MongoDB shell version v3.4.9
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.9
Server has startup warnings:
2017-10-25T00:49:58.983+0000 I STORAGE [initandlisten]
2017-10-25T00:49:58.983+0000 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2017-10-25T00:49:58.983+0000 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem
2017-10-25T00:49:59.076+0000 I CONTROL [initandlisten]
2017-10-25T00:49:59.076+0000 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-10-25T00:49:59.076+0000 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2017-10-25T00:49:59.076+0000 I CONTROL [initandlisten]
Versions
c:\Program Files\MongoDB\Server\3.4\bin>docker --version
Docker version 17.09.0-ce, build afdb6d4
c:\Program Files\MongoDB\Server\3.4\bin>docker-compose --version
docker-compose version 1.16.1, build 6d1ac219
I'm using docker for windows that is run via hyper-v.
Whats wrong with my compose file and why it works via docker run but doesn't work via docker-compose. I'm scratching my head and googling without any luck for hours
Other port sharing via docker-compose ( e.g. nginx, postgresql) works perfectly fine.
UPDATE
Asked friend on ubuntu to try. Same behaviour. So its reproducible and its not specific to windows at all.. Works via docker, doesnt work via docker-compose. Even when i try to connect via telnet mongo logs show connect attempts when running via docker, but nothing shown when run via compose.
Also I see a difference in docker ps when run via compose vs when run via docker.
Ports on compose listed as
( 27017/tcp, 0.0.0.0:27017->21017/tcp )
vs
(0.0.0.0:27017->21017/tcp )
on docker itself.
It missed first 27017/tcp part which might be the issue, but no idea why.
Ok, the problem is super stupid and simple.
ports: - "27017:21017"
second port 21017 instead of 27017. How to waste full day due to typo
If you are on linux it works fine. When you run container in windows you need to do port farwarding.
netsh interface portproxy add v4tov4 listenport=27017 listenaddress=localhost connectport=27017 connectaddress=192.168.99.100(IP of the Docker)
Whatever the call comming to loopback it will get redirected to container with the docker host.
Here is the helping discussion on port farwarding in windows with docker Solution for Windows hosts
This lines I'm using docker for windows that is run via hyper-v., say that you ae on Windows and docker will not be the loopback(127.0.0.1), you have to forward the port.

Robo 3T Error : Network is unreachable

I am trying to connect Robo 3T to my online database and it doesn't seem to be working. I am able to connect to local database with it. I tried connecting using MongoDB Compass and the Details and Auth are working fine and I am able to connect. But when I connect with the same details in Robo 3T, it doesn't seem to be working. How do I fix this?
I am using Robo 3T Version 1.1
I tried same with Robomongo 1.0, and still getting the same error
Just change your bind_ip in /etc/mongod.conf from 127.0.0.1 to 0.0.0.0 then restart the service, and it works for me~
If you get the following error then you should also check the following:
The atlas servers at least require this setting, if you do not choose it, then you generally get the Network is unreachable message.
Also if you are using Atlas then you should check the Authentication tab and select SCRAM-SHA-1, however this generally results in an authentication error not a network unreachable one.
A better solution is to comment out or remove the bindIp setting from the config file /etc/mongod.conf
You must restart the service for the change to take effect
I also meet this problem when I use Robo 3T on Mac. I think there are some things you need to check to help you know what's the problem.
First try to ping the mongo server in your terminal to see whether you can get responses. If so, that's means you may set wrong mongo config in you Robo 3T.
If you cannot get the response, that means there is something wrong with your network. You should check your DNS and your network gateway. For example my DNS is 172.16.* and my network gateway (execute ifconig and check en0) is 172.17.*. And they are not belong to the same network segment. (Actually, even if they are on the same network segment, things won't work if someone polluted your DNS server.)
That's the problem. The DNS that you are using cannot interpret your mongo host correctly. Someone may had polluted this DNS server.
You can have a try on ping xxx(your mongo-server) #8.8.8.8, which will use 8.8.8.8 as your DNS. If everything goes well, then you get the sollution.
Sollution: Manually set DNS for your devices. For example, Google's public DNS, 8.8.8.8 and 8.8.4.4.
Actually, if you run dig xxx(your mongo-server) before and after you manually set DNS, you may find the response Ip differently.
Go Inside bin folder of MongoDB and run mongod command:- C:\Program Files\MongoDB\Server\4.2\bin
then open command prompt at this location and run mongod command & then try to connect with Robo 3T . It works for me.
Also create data folder inside your C: drive & then create a db named folder inside data folder. that's it.
Start the MongoDB service from the task manager.
Worked for me.
In my case both mongod and mongo.exe was throwing a 100 error code.
I had this symptom, and the ultimate fix is not yet captured in an answer here.
I was trying to connect to a mongo instance in the cloud using Robo 3T, and I was getting the "Network is unreachable" message.
Oddly, I could connect from using Robo 3T inside a Parallels VM on the same machine.
This led me to try the full Studio 3T on my mac, which could also connect just fine.
Ultimately, I discovered that there was an old dotfile from an ancient version of Robomongo that was causing the problem. rm -rf .config/robomongo did the trick. Now I can connect with the ordinary, free Robo 3T.
I'm guessing that I had an expired trial of Robomongo, from back before it was free, perhaps?
sorry if i'm late to this but i was running through the same issue all morning. You have to go through a few things first so you can troubleshoot easily
Restart the database from the terminal, hitting the database at the correct path and let it run in the background.
if the database is running then go through checking the local host address, and replace it with 127.0.0.1 instead of the generic localhost:27017
This might help, my robo mongo server is hosted in cloud. I have setup the mongodb but could not connect to it using Robo3T. Keeps telling network timedout (this means network problem). Been reading a lot to figure out the cause, suddenly I remembered I have also a security group in my cloud network. Just include the mongod port 27017 in the list of allowed incoming. That's it!
You may be seeing the following issue when starting the Robo 3T Application:
Just follow these steps, and you are good to go:
I'm using MacOS, so in your terminal use the following command to start your MonogDB Server:
/Users/vanthoff/mongodb/bin/mongod --dbpath=/Users/vanthoff/mongodb-data
mongodb-data: Directory you must have created to store all your Data.
After starting the server, go to RoboT 3T Application and connect to the server. It will start working. You can also Test it by double clicking you MongoDB Server name. It will look something like this when it starts working:
I hope it's going to work for you too. Amigos..!! 🙂
Go to services.msc and then search for mongodb server and then run the server in running status.
I have solved my error in this way.
For me, reinstall mongodb and restart my computer worked fine.
As said above, this is probably due to BindIp, if you use mac and brew to install it you won't find anything in /etc/mongod.conf instead you find it in /usr/local/etc/mongod.conf
systemLog:
destination: file
path: /usr/local/var/log/mongodb/mongo.log
logAppend: true
storage:
dbPath: /usr/local/var/mongodb
net:
bindIp: 127.0.0.1
Change BindIp with caution!
And same goes for running it, to start MongoDB manualy use:
mongod --config /usr/local/etc/mongod.conf
or configure autostart on login with launchd by typing:
brew services start mongodb
I've also encountered corrupted data files on my local computer here:
/usr/local/var/mongodb
just removed them and it worked, you could see in the log that errors like:
** IMPORTANT: UPGRADE PROBLEM: The data files need to be fully upgraded to version 3.6 before attempting an upgrade to 4.0; see http://dochub.mongodb.org/core/4.0-upgrade-fcv for more details.
2018-08-01T00:15:50.220+0200 I NETWORK [initandlisten] shutdown: going to close listening sockets...
2018-08-01T00:15:50.220+0200 I NETWORK [initandlisten] removing socket file: /tmp/mongodb-27017.sock
2018-08-01T00:15:50.224+0200 I STORAGE [initandlisten] WiredTigerKVEngine shutting down
2018-08-01T00:15:50.303+0200 I STORAGE [initandlisten] Downgrading WiredTiger datafiles.
2018-08-01T00:15:50.501+0200 I STORAGE [initandlisten] WiredTiger message [1533075350:501686][3594:0x7fffb492e380], txn-recover: Main recovery loop: starting at 14/3712
2018-08-01T00:15:50.598+0200 I STORAGE [initandlisten] WiredTiger message [1533075350:598867][3594:0x7fffb492e380], txn-recover: Recovering log 14 through 15
2018-08-01T00:15:50.664+0200 I STORAGE [initandlisten] WiredTiger message [1533075350:663976][3594:0x7fffb492e380], txn-recover: Recovering log 15 through 15
2018-08-01T00:15:50.715+0200 I STORAGE [initandlisten] WiredTiger message [1533075350:715398][3594:0x7fffb492e380], txn-recover: Set global recovery timestamp: 0
2018-08-01T00:15:51.002+0200 I STORAGE [initandlisten] shutdown: removing fs lock...
2018-08-01T00:15:51.005+0200 I CONTROL [initandlisten] now exiting
2018-08-01T00:15:51.005+0200 I CONTROL [initandlisten] shutting down with code:62
This means mongo server is not started.
You need to run mongod command on the terminal to start the server.
if you do not have mongo db installed on your machine. Download and install from the Link.
Start your command prompt on windows.Go to the bin folder of Mongodb through command prompt and type mongod and enter.Now try to access again

mongoDB test error

I came to know about mongoDB and looked for test.So I made it install and then for test when I used command mongo on terminal it showed an error like this
MongoDB shell version: 1.8.2
connecting to: test
Sun Jul 31 01:06:07 Error: couldn't connect to server 127.0.0.1 shell/mongo.js:79
exception: connect failed
So can someone tell me what is the problem.I am using ubuntu 11.04.For installation instruction I had used this site.I am newbie to this mongoDB so please helpe me.Any help will be highly appreciable.
All you need to do is open 2 terminal tabs. In one, run
mongod
which starts the MongoDB server.
In the other, run
mongo
which is the shell that connects to your MongoDB server.
It looks like MongoDB isn't running. Can you connect to the web interface in your browser?
http://localhost:28017
Also, do you see the process running on your machine? You should see an entry for mongod when running ...
$ top
or
$ ps aux
why not install mongodb from 10gen's own debian repository? much easier and more likely to work
http://www.mongodb.org/display/DOCS/Ubuntu+and+Debian+packages
To see if mongodb is running, this also helps:
sudo service mongodb status
if it is running, and you still get the same error, then it must be the weird localhost bug that mongodb has. it assumes localhost is 127.0.1.1 for some reason. try
mongo 127.0.1.1
I had the same problem. Just try to create folder c:\data and next c:\data\db