Connection being refused and not sure what to do about it

4,355 views
Skip to first unread message

Code Writer

unread,
Sep 13, 2013, 12:18:18 AM9/13/13
to mongod...@googlegroups.com
Connection being refused and not sure what to do about it.

Here is my code in the constructor pf a class called MongoDB_Manager: (What am I doing wrong or omitting?!)
public class MongoDB_Manager
{
 
MongoClient mongoClient;
  DB db
;

 
public MongoDB_Manager()
 
{
   
try
   
{
     
//mongoClient = new MongoClient(); //connects to mongo server locally  (seems to work)
     
//mongoClient = new MongoClient("localhost",27017); //connects to mongo server locally (seems to work)
      mongoClient
= new MongoClient("localhost"); //connects to mongo server locally
      db
= mongoClient.getDB("tradebot_DB"); // connect to a database --implicitly creates database if none exists
     
DBCollection collection = db.getCollection("symbol"); // --implicitly creates collection if none exists
     
BasicDBObject o = new BasicDBObject(); // create a document object
      o
.put("symbol_name", "VRSK"); //define field and value

     
//==========THE FOLLOWING LINE IS WHERE IT BARFS=========
      collection
.insert(o, WriteConcern.ACKNOWLEDGED); //insert document into collection    
     
     
DBCursor cursorDoc = collection.find();
     
while (cursorDoc.hasNext())
     
{
       
System.out.println(cursorDoc.next());
     
}

   
}
   
catch (UnknownHostException ex)
   
{
     
Logger.getLogger(MongoDB_Manager.class.getName()).log(Level.SEVERE,
       
null, ex);
   
}
 
}
}

Here is the stack trace:
debug:
EST selected
Sep 12, 2013 10:04:28 PM com.mongodb.DBTCPConnector initDirectConnection
WARNING: Exception executing isMaster command on localhost/127.0.0.1:27017
java.net.ConnectException: Connection refused: connect
    at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:75)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
    at java.net.Socket.connect(Socket.java:579)
    at com.mongodb.DBPort._open(DBPort.java:223)
    at com.mongodb.DBPort.go(DBPort.java:125)
    at com.mongodb.DBPort.go(DBPort.java:106)
    at com.mongodb.DBPort.findOne(DBPort.java:162)
    at com.mongodb.DBPort.runCommand(DBPort.java:170)
    at com.mongodb.DBTCPConnector.initDirectConnection(DBTCPConnector.java:533)
    at com.mongodb.Mongo.getMaxBsonObjectSize(Mongo.java:611)
    at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:232)
    at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:204)
    at com.mongodb.DBCollection.insert(DBCollection.java:148)
    at com.mongodb.DBCollection.insert(DBCollection.java:91)
    at Communication.MongoDB_Manager.<init>(MongoDB_Manager.java:43)
    at windows.TradeBotMainWindow.<init>(TradeBotMainWindow.java:915)
    at windows.TradeBotMainWindow$14.run(TradeBotMainWindow.java:1845)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:727)
    at java.awt.EventQueue.access$200(EventQueue.java:103)
    at java.awt.EventQueue$3.run(EventQueue.java:688)
    at java.awt.EventQueue$3.run(EventQueue.java:686)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:697)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)

Sep 12, 2013 10:04:29 PM com.mongodb.DBTCPConnector initDirectConnection
WARNING: Exception executing isMaster command on localhost/127.0.0.1:27017
java.net.ConnectException: Connection refused: connect
    at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:75)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
    at java.net.Socket.connect(Socket.java:579)
    at com.mongodb.DBPort._open(DBPort.java:223)
    at com.mongodb.DBPort.go(DBPort.java:125)
    at com.mongodb.DBPort.go(DBPort.java:106)
    at com.mongodb.DBPort.findOne(DBPort.java:162)
    at com.mongodb.DBPort.runCommand(DBPort.java:170)
    at com.mongodb.DBTCPConnector.initDirectConnection(DBTCPConnector.java:533)
    at com.mongodb.DBTCPConnector.checkMaster(DBTCPConnector.java:512)
    at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:134)
    at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:115)
    at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:248)
    at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:204)
    at com.mongodb.DBCollection.insert(DBCollection.java:148)
    at com.mongodb.DBCollection.insert(DBCollection.java:91)
    at Communication.MongoDB_Manager.<init>(MongoDB_Manager.java:43)
    at windows.TradeBotMainWindow.<init>(TradeBotMainWindow.java:915)
    at windows.TradeBotMainWindow$14.run(TradeBotMainWindow.java:1845)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:727)
    at java.awt.EventQueue.access$200(EventQueue.java:103)
    at java.awt.EventQueue$3.run(EventQueue.java:688)
    at java.awt.EventQueue$3.run(EventQueue.java:686)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:697)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)

Sep 12, 2013 10:04:30 PM com.mongodb.DBPortPool gotError
WARNING: emptying DBPortPool to localhost/127.0.0.1:27017 b/c of error
java.net.ConnectException: Connection refused: connect
    at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:75)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
    at java.net.Socket.connect(Socket.java:579)
    at com.mongodb.DBPort._open(DBPort.java:223)
    at com.mongodb.DBPort.go(DBPort.java:125)
    at com.mongodb.DBPort.go(DBPort.java:102)
    at com.mongodb.DBPort.say(DBPort.java:97)
    at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:140)
    at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:115)
    at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:248)
    at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:204)
    at com.mongodb.DBCollection.insert(DBCollection.java:148)
    at com.mongodb.DBCollection.insert(DBCollection.java:91)
    at Communication.MongoDB_Manager.<init>(MongoDB_Manager.java:43)
    at windows.TradeBotMainWindow.<init>(TradeBotMainWindow.java:915)
    at windows.TradeBotMainWindow$14.run(TradeBotMainWindow.java:1845)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:727)
    at java.awt.EventQueue.access$200(EventQueue.java:103)
    at java.awt.EventQueue$3.run(EventQueue.java:688)
    at java.awt.EventQueue$3.run(EventQueue.java:686)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:697)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)

Exception in thread "AWT-EventQueue-0" com.mongodb.MongoException$Network: Write operation to server localhost/127.0.0.1:27017 failed on database tradebot_DB
    at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:153)
    at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:115)
    at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:248)
    at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:204)
    at com.mongodb.DBCollection.insert(DBCollection.java:148)
    at com.mongodb.DBCollection.insert(DBCollection.java:91)
    at Communication.MongoDB_Manager.<init>(MongoDB_Manager.java:43)
    at windows.TradeBotMainWindow.<init>(TradeBotMainWindow.java:915)
    at windows.TradeBotMainWindow$14.run(TradeBotMainWindow.java:1845)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:727)
    at java.awt.EventQueue.access$200(EventQueue.java:103)
    at java.awt.EventQueue$3.run(EventQueue.java:688)
    at java.awt.EventQueue$3.run(EventQueue.java:686)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:697)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
Caused by: java.net.ConnectException: Connection refused: connect
    at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:75)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
    at java.net.Socket.connect(Socket.java:579)
    at com.mongodb.DBPort._open(DBPort.java:223)
    at com.mongodb.DBPort.go(DBPort.java:125)
    at com.mongodb.DBPort.go(DBPort.java:102)
    at com.mongodb.DBPort.say(DBPort.java:97)
    at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:140)
    ... 22 more
BUILD SUCCESSFUL (total time: 1 minute 16 seconds)



Keith Branton

unread,
Sep 13, 2013, 1:38:43 AM9/13/13
to mongod...@googlegroups.com
Sam,

I just tested your code and with minor changes to get it to compile and run as an application it worked for me. 

Is your mongo instance running? 

You can issue the command...


...to test that mongo is working as expected.

FYI the code I executed was...


import java.net.UnknownHostException;

import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.MongoClient;
import com.mongodb.WriteConcern;

public class MongoDB_Manager {

public static void main(final String[] args) {
MongoClient mongoClient;
DB db;
try {
// mongoClient = new MongoClient(); //connects to mongo server locally (seems to work)
// mongoClient = new MongoClient("localhost",27017); //connects to mongo server locally (seems to work)
mongoClient = new MongoClient("localhost"); // connects to mongo server locally
db = mongoClient.getDB("tradebot_DB"); // connect to a database --implicitly creates database if none exists
DBCollection collection = db.getCollection("symbol"); // --implicitly creates collection if none exists
BasicDBObject o = new BasicDBObject(); // create a document object
o.put("symbol_name", "VRSK"); // define field and value

// ==========THE FOLLOWING LINE IS WHERE IT BARFS=========
collection.insert(o, WriteConcern.ACKNOWLEDGED); // insert document into collection

DBCursor cursorDoc = collection.find();
while (cursorDoc.hasNext()) {
System.out.println(cursorDoc.next());
}

} catch (UnknownHostException ex) {
ex.printStackTrace();
}
}
}




--
--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com
To unsubscribe from this group, send email to
mongodb-user...@googlegroups.com
See also the IRC channel -- freenode.net#mongodb
 
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Code Writer

unread,
Sep 13, 2013, 3:23:48 PM9/13/13
to mongod...@googlegroups.com
Keith,

Thank you for your quick response!

I did the following as per your suggestion: (You were right about the connection failing at the command prompt! ....but what should I do now?   I followed the installation instructions; downloaded and installed for Win7 64 bit, and created mongodb and data\db directories. I also set the firewall to "allow".)

In an Administrator: Command Prompt:


Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\>mongodb\bin\mongo.exe
MongoDB shell version: 2.4.6
connecting to: test
Fri Sep 13 12:55:14.753 Error: couldn't connect to server 127.0.0.1:27017 at src
/mongo/shell/mongo.js:145
exception: connect failed

C:\>mongodb\bin\mongo 127.0.0.1:27017/tradebot_DB
MongoDB shell version: 2.4.6
connecting to: 127.0.0.1:27017/tradebot_DB
Fri Sep 13 12:58:45.294 Error: couldn't connect to server 127.0.0.1:27017 at src
/mongo/shell/mongo.js:147
exception: connect failed

C:\>

Here are the directories:


C:\>cd mongodb

C:\mongodb>dir
 Volume in drive C has no label.
 Volume Serial Number is FC53-4888

 Directory of C:\mongodb

09/12/2013  01:43 PM    <DIR>          .
09/12/2013  01:43 PM    <DIR>          ..
09/12/2013  01:43 PM    <DIR>          bin
09/12/2013  01:43 PM            35,181 GNU-AGPL-3.0
09/12/2013  01:43 PM             1,359 README
09/12/2013  01:43 PM            18,848 THIRD-PARTY-NOTICES
               3 File(s)         55,388 bytes
               3 Dir(s)  415,073,787,904 bytes free

 Directory of C:\mongodb


C:\mongodb>cd bin

C:\mongodb\bin>dir
 Volume in drive C has no label.
 Volume Serial Number is FC53-4888

 Directory of C:\mongodb\bin

09/12/2013  01:43 PM    <DIR>          .
09/12/2013  01:43 PM    <DIR>          ..
09/12/2013  01:43 PM        14,893,056 bsondump.exe
09/12/2013  01:43 PM         7,985,152 mongo.exe
09/12/2013  01:43 PM        14,951,936 mongod.exe
09/12/2013  01:43 PM        95,947,776 mongod.pdb
09/12/2013  01:43 PM        14,943,232 mongodump.exe
09/12/2013  01:43 PM        14,898,176 mongoexport.exe
09/12/2013  01:43 PM        14,922,240 mongofiles.exe
09/12/2013  01:43 PM        14,923,264 mongoimport.exe
09/12/2013  01:43 PM        14,893,056 mongooplog.exe
09/12/2013  01:43 PM        14,896,640 mongoperf.exe
09/12/2013  01:43 PM        14,937,600 mongorestore.exe
09/12/2013  01:43 PM        11,439,616 mongos.exe
09/12/2013  01:43 PM        73,616,384 mongos.pdb
09/12/2013  01:43 PM        14,945,280 mongostat.exe
09/12/2013  01:43 PM        14,898,176 mongotop.exe
              15 File(s)    353,091,584 bytes
               2 Dir(s)  415,070,945,280 bytes free

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.


C:\>dir
 Volume in drive C has no label.
 Volume Serial Number is FC53-4888

 Directory of C:\

09/21/2012  08:19 PM    <DIR>          Boot
09/21/2012  08:19 PM           383,562 bootmgr
06/26/2013  07:46 PM    <DIR>          Bovada
09/12/2013  01:46 PM    <DIR>          data
08/30/2013  01:25 PM    <DIR>          DataManager
06/27/2011  06:43 PM    <DIR>          Intel
09/12/2013  01:43 PM    <DIR>          mongodb
06/27/2011  07:12 PM    <DIR>          NVIDIA
07/13/2009  09:20 PM    <DIR>          PerfLogs
07/11/2013  10:36 PM    <DIR>          Program Files
09/10/2013  10:21 PM    <DIR>          Program Files (x86)
07/07/2013  10:09 PM    <DIR>          Qt
06/27/2011  06:48 PM    <DIR>          RaidTool
08/14/2013  11:05 PM    <DIR>          SQLite3
09/03/2013  11:46 AM    <DIR>          TradeBot
06/29/2013  11:41 PM    <DIR>          Users
09/11/2013  08:57 PM    <DIR>          Windows
09/07/2012  06:19 PM         1,008,394 Windows6.1-KB2731284-v3-x64.msu
06/11/2013  02:29 AM    <DIR>          ZipSnap21
               2 File(s)      1,391,956 bytes
              17 Dir(s)  415,073,787,904 bytes free

C:\>cd mongodb

C:\mongodb>dir
 Volume in drive C has no label.
 Volume Serial Number is FC53-4888

 Directory of C:\mongodb

09/12/2013  01:43 PM    <DIR>          .
09/12/2013  01:43 PM    <DIR>          ..
09/12/2013  01:43 PM    <DIR>          bin
09/12/2013  01:43 PM            35,181 GNU-AGPL-3.0
09/12/2013  01:43 PM             1,359 README
09/12/2013  01:43 PM            18,848 THIRD-PARTY-NOTICES
               3 File(s)         55,388 bytes
               3 Dir(s)  415,073,787,904 bytes free

C:\mongodb>cd bin

C:\mongodb\bin>dir
 Volume in drive C has no label.
 Volume Serial Number is FC53-4888

 Directory of C:\mongodb\bin

09/12/2013  01:43 PM    <DIR>          .
09/12/2013  01:43 PM    <DIR>          ..
09/12/2013  01:43 PM        14,893,056 bsondump.exe
09/12/2013  01:43 PM         7,985,152 mongo.exe
09/12/2013  01:43 PM        14,951,936 mongod.exe
09/12/2013  01:43 PM        95,947,776 mongod.pdb
09/12/2013  01:43 PM        14,943,232 mongodump.exe
09/12/2013  01:43 PM        14,898,176 mongoexport.exe
09/12/2013  01:43 PM        14,922,240 mongofiles.exe
09/12/2013  01:43 PM        14,923,264 mongoimport.exe
09/12/2013  01:43 PM        14,893,056 mongooplog.exe
09/12/2013  01:43 PM        14,896,640 mongoperf.exe
09/12/2013  01:43 PM        14,937,600 mongorestore.exe
09/12/2013  01:43 PM        11,439,616 mongos.exe
09/12/2013  01:43 PM        73,616,384 mongos.pdb
09/12/2013  01:43 PM        14,945,280 mongostat.exe
09/12/2013  01:43 PM        14,898,176 mongotop.exe
              15 File(s)    353,091,584 bytes
               2 Dir(s)  415,070,945,280 bytes free

C:\>cd data

C:\data>dir
 Volume in drive C has no label.
 Volume Serial Number is FC53-4888

 Directory of C:\data

09/12/2013  01:46 PM    <DIR>          .
09/12/2013  01:46 PM    <DIR>          ..
09/12/2013  01:52 PM    <DIR>          db
               0 File(s)              0 bytes
               3 Dir(s)  415,073,345,536 bytes free

C:\data>cd db

C:\data\db>dir
 Volume in drive C has no label.
 Volume Serial Number is FC53-4888

 Directory of C:\data\db

09/12/2013  01:52 PM    <DIR>          .
09/12/2013  01:52 PM    <DIR>          ..
09/12/2013  01:53 PM    <DIR>          journal
09/12/2013  01:51 PM        67,108,864 local.0
09/12/2013  01:51 PM        16,777,216 local.ns
09/12/2013  01:53 PM                 0 mongod.lock
               3 File(s)     83,886,080 bytes
               3 Dir(s)  415,073,349,632 bytes free
==============================================================================================

Code Writer

unread,
Sep 13, 2013, 3:33:51 PM9/13/13
to mongod...@googlegroups.com
Keith,

In Control Panel>System Security> Windows Firewall>Allowed Programs, mongod is checked for the Hone/Work (Private) access, no Public access.

Code Writer

unread,
Sep 13, 2013, 3:45:40 PM9/13/13
to mongod...@googlegroups.com
Keith,

I downloaded     mongodb-win32-x86_64-2008plus-2.4.6  because I have Win7 Ultimate 64 bit Service Pack 1

Code Writer

unread,
Sep 13, 2013, 4:00:16 PM9/13/13
to mongod...@googlegroups.com
Keith,

I have Windows 7 Ultimate 64 bit with Service Pack 1.

I downloaded and installed mongodb-win32-x86_64-2008plus-2.4.6.zip .......but, I noticed there is a mongodb-win32-x86_64-2.4.6.zip .......should I have downloaded and installed that instead?! 

I got the impression that mongodb-win32-x86_64-2008plus-2.4.6.zip was for Windows 7 64 bit from:

MongoDB distribution for Windows 64-bit ships with two flavours:
  • one for Windows server 2008 and Windows 7, Server 2012 (download link “*2008R2+” )
  • other for rest of 64-bit Windows OS.




Code Writer

unread,
Sep 13, 2013, 4:17:14 PM9/13/13
to mongod...@googlegroups.com
Keith,

I found out that if I do C:\>mongodb\bin\mongod.exe  it starts a mongo server succesfully.
Then when I do your command of:  C:\>mongodb\bin\mongo 127.0.0.1:27017/tradebot_DB it successfully connected!!

Now, this means that the server must run before I try database access, but how do I get the server to run when I execute my java program?
Is there something else I need to set up?
What are you doing to ensure a server is running when executing a java program?






Russell Bateman

unread,
Sep 13, 2013, 4:28:38 PM9/13/13
to mongod...@googlegroups.com
MongoDB typically runs all the time, as a service. If you don't wish to have to launch it each time you want to test your application, you should run your local copy as a service on your development host. See http://docs.mongodb.org/manual/tutorial/install-mongodb-on-windows/ .

Code Writer

unread,
Sep 13, 2013, 8:14:09 PM9/13/13
to mongod...@googlegroups.com
Keith,

Can't I execute a batch file within a java application to launch the mongodb server prior to accessing a database with MongoClient?

I don't like the idea of having MongoDB run as service all the time. Too often I don't need it, but yet it would still be running.

Keith Branton

unread,
Sep 13, 2013, 8:28:10 PM9/13/13
to mongod...@googlegroups.com
Sam,

You probably could. I just leave mongod running as a service all the time on my machine. When I'm not using it I don't even notice it. I have only really used linux for the past 5 years so my windows knowledge is really rusty.

Executing a command from java is pretty easy. This so seems relevant to running a windows batch file from java:


You'd need to either shut down mongod whenever your process stops or check if mongod is already running (maybe easier in the batch file) and not start another copy if it is already running.

Seriously though - I'd try running it as a service first and see if that actually causes you any issues.



Code Writer

unread,
Sep 13, 2013, 10:50:28 PM9/13/13
to mongod...@googlegroups.com
Keith,

I tried the batch file idea, but the big problem there was getting the MongoDB server to gracefully stop with the DOS command prompt window closing as well.

So, ....after all this churning, I followed your suggestion to set up the MongoDB server as a service.

Thank you so much for your patience and help
Reply all
Reply to author
Forward
0 new messages