Running the program from eclipse is able to insert data into Mongo DB of the local machine, but not into Mongo DB of the remote machine

Here is the code I used:

package testing;
import com.mongodb.*;

public class MongoTest {

public static void main(String args[])
{
    try
    {
        MongoClient cli=new MongoClient("10.6.9.227",27017);
        DB dtbs=cli.getDB("test");
        System.out.println("Connection to DB successful");
        DBCollection col=dtbs.getCollection("newcol");
        BasicDBObject record=new    BasicDBObject("name","student1").append("sem","6");
        col.insert(record);
        System.out.println("Successfully Inserted into collection");
    }
    catch(Exception e)
    { 
        System.out.println(e.getMessage()); 
    }
}}

      

This code fits nicely into the same computer that this eclipse program is running from (which is set when the cli object is initialized 10.6.9.57).

But, when I try to do the same on a remote machine on the same local network (which is given by ip 10.6.9.227), this is what is displayed in the eclipse console:

Successful connection to DB Timeout after 10000 ms waiting for the server corresponding to AnyServerSelector {}. Cluster state client view: {type = Unknown, servers = [{address = 10.6.9.227: 28017, type = Unknown, state = Connection, exception = {java.lang.NullPointerException}}]

The machine 10.6.9.57 runs on Windows OS. I am launching the Eclipse program from here. The remote machine 10.6.9.227 is running Debian Squeeze OS.

I checked to see if the open ports are open via a command netstat

on system 227:

 :~$ sudo netstat -lntup
    >Active Internet connections (only servers)
    >Proto Recv-Q Send-Q Local Address           Foreign Address         State                                                                                                  PID/Program name
    >tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN                                                                                                 848/portmap
   >tcp        0      0 127.0.0.1:28017         0.0.0.0:*               LISTEN                                                                                              2421/mongod
   >tcp        0      0 0.0.0.0:49396           0.0.0.0:*               LISTEN                                                                                              860/rpc.statd
   >tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN                                                                                              1566/sshd
   >tcp        0      0 127.0.0.1:5984          0.0.0.0:*               LISTEN                                                                                              1163/beam.smp
   >tcp        0      0 127.0.0.1:27017         0.0.0.0:*               LISTEN                                                                                              2421/mongod
   >tcp6       0      0 :::22                   :::*                    LISTEN                                                                                              1566/sshd
   >udp        0      0 0.0.0.0:54866           0.0.0.0:*                                                                                                                   860/rpc.statd
   >udp        0      0 0.0.0.0:612             0.0.0.0:*                                                                                                                   860/rpc.statd
   >udp        0      0 0.0.0.0:32870           0.0.0.0:*                                                                                                                   1260/avahi-daemon:
   >udp        0      0 0.0.0.0:5353            0.0.0.0:*                                                                                                                   1260/avahi-daemon:
   >udp        0      0 0.0.0.0:111             0.0.0.0:*                                                                                                                   848/portmap
   >udp        0      0 10.6.9.227:123          0.0.0.0:*                                                                                                                   1610/ntpd
   >udp        0      0 127.0.0.1:123           0.0.0.0:*                                                                                                                   1610/ntpd
   >udp        0      0 0.0.0.0:123             0.0.0.0:*                                                                                                                   1610/ntpd
   >udp6       0      0 :::5353                 :::*                                                                                                                        1260/avahi-daemon:
   >udp6       0      0 :::123                  :::*                                                                                                                        1610/ntpd
   >udp6       0      0 :::50061                :::*                                                                                                                          1260/avahi-daemon:

      

These ports are only open and I can also paste into this local machine from my own command line (via putty):

> db.newcol.insert({name:"firststudent"},{sem:"5"});
> db.newcol.find()
{ "_id" : ObjectId("5571366e1031fc034ac63013"), "name" : "firststudent" }

      

Also, this is what the Mongo DB log file looks like in / var / log / mongodb:

Fri Jun  5 10:39:02 Mongo DB : starting : pid = 2421 port = 27017 dbpath = /var/lib/mongodb master = 0 slave = 0  64-bit
Fri Jun  5 10:39:02 db version v1.4.4, pdfile version 4.5
Fri Jun  5 10:39:02 git version: nogitversion
Fri Jun  5 10:39:02 sys info: Linux bobek-a0 2.6.32-trunk-amd64 #1 SMP Sun Jan 10 22:40:40 UTC 2010 x86_64 BOOST_LIB_VERSION=1_42
Fri Jun  5 10:39:02 waiting for connections on port 27017
Fri Jun  5 10:39:02 web admin interface listening on port 28017

      

I just can't seem to work out why a java program launched from eclipse of a machine connected to the same local network is not able to do this. I have included mongo-java-driver-2.13.0-rc1.jar. I even tried to stop and restart the mongo db in the remote machine and repeat this process several times. But still unable to insert. Any help?

+3


source to share


1 answer


  • telnet

    from your window to the remote mongo box to the port 27017

    . See if you can.
  • connect to remote mongo from your local mongo client (not java / eclipse), see if it succeeds. Not from it own localhost, but from your computer to remote via the mongo client.
  • Check the mongo configuration on the remote machine (especially check the /etc/mongod.conf

    value for the bind_ip parameter.


0


source







All Articles