I'm getting the following error:
נוב 08, 2013 12:05:46 PM com.mongodb.DBTCPConnector initDirectConnection
WARNING: Exception executing isMaster command on localhost/127.0.0.1:27017
java.io.IOException: couldn't connect to [localhost/127.0.0.1:27017] bc:java.net.ConnectException: Connection refused: connect
at com.mongodb.DBPort._open(DBPort.java:214)
at com.mongodb.DBPort.go(DBPort.java:107)
at com.mongodb.DBPort.go(DBPort.java:88)
at com.mongodb.DBPort.findOne(DBPort.java:143)
at com.mongodb.DBPort.runCommand(DBPort.java:148)
at com.mongodb.DBTCPConnector.initDirectConnection(DBTCPConnector.java:548)
at com.mongodb.DBTCPConnector.checkMaster(DBTCPConnector.java:527)
at com.mongodb.DBTCPConnector.innerCall(DBTCPConnector.java:277)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:257)
at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:310)
at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:295)
at com.mongodb.DB.getCollectionNames(DB.java:412)
at Main.Main.main(Main.java:26)
my code is simple (my first time with mongo):
MongoClient Client = new MongoClient( "localhost" , 27017 );
DB db = Client.getDB("qw");
DBCollection coll[] = new DBCollection[4];
Set<String> colls = db.getCollectionNames();
for(String s: colls)
System.out.println(s);
what is the problem?
Possibly you haven't started the Mongo server.
Open a shell and type
mongod
On the file system, you can start it from $MONGO_INSTALL_PATH/bin/mongod
.
Don't close the shell and then try to run your code again.
More info:
Try restarting your mongo. I had the same problem, and restarting solved it for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With