I installed mongodb in Ubuntu14.04 server
I was not able to connect to mongodb via \"mongoimport\", \"mongodump\", \"mongostat\", etc. It always show \"no reachable
You need to provide host option try the following command :
mongoimport --host=127.0.0.1 -d dbName -c collectionName --file output.txt
A temporary workaround is to add the host
param to your mongoimport
call, letting mongo know that the host is your own machine (127.0.0.1
):
mongoimport --host=127.0.0.1
The full command in your case is then:
mongoimport --host=127.0.0.1 \
--db test --collection restaurants --drop --file dataset.json
(Source: ranjeetcao @ mongorestore Failed: no reachable servers)
Update:
Updating to Mongo >= 3.0.7 should solve the issue
(Source: Colin Marshall @ mongorestore Failed: no reachable servers)
Update 2:
It seems the Bug is still happening for some users.
There's also an open JIRA issue here.
(Source: James Chien @ this question thread)
Update 3:
In some cases, this can be caused by Mongo running as a ReplicaSet. To solve this, as far as I've seen, one can either disable the ReplicaSet functionality or reset it. See:
(Source: Maxim Yefremov @ mongorestore Failed: no reachable servers)
To provide the options host and port
mongoimport --host X.X.X.X --port 27017 --db dbName --collection collectionName --file fileName.json --jsonArray
Adding another answer for those who are struggling with the same issue while using MongoDB Atlas.
I tried to follow the offical guides like Seed with mongorestore and Load File with mongoimport but received the same no reachable servers
error.
I tried to change the command arguments over and over - nothing changed.
But then I navigated inside my cluster to the "Command Line Tools" tab and saw the exact command I should run for mongorestore
, mongodump
, mongoimport
,mongoexport
etc':
Adding as inline the full command:
mongorestore --host
<cluster-name>-shard-0/
<cluster-name>-shard-00-00-obe3i.mongodb.net:27017,
<cluster-name>-shard-00-01-obe3i.mongodb.net:27017,
<cluster-name>-shard-00-02-obe3i.mongodb.net:27017
--ssl
--username <User-Name>
--password <PASSWORD>
--authenticationDatabase admin
The mongorestore
comand can be replaced with mongodump
,mongoimport
,mongoexport
etc'.
(*) Prefer copying the command directly from dashboard because the DNS of the replica-sets might change.
(**) MongoDB shell version v4.2.5.
I went ahead and downloaded MongoDB Compass and used the connection string from Atlas for
and that connection worked like a charm.
After that I went ahead and added the data using the Add Data
option and uploaded the file which i want to mongoimport
For someone using Mongo Atlas and json
file for import into collection:
mongoimport --uri mongodb+srv://<user>:<password>@your-cluster.xxxx.mongodb.net/<db> -c <collection> --file import.json --jsonArray