title: store data to MongoDB Collection in millisecond
body: <p>I write application in java to store data from UDP broadcast and store them to MongoDB.
  UDP sent in millisecond and it contain about text file separate by coma (about 30 fields).</p>
  
  <p>But i meet the problem as follow (problem show only in 4-5 minutes I run the program).</p>
  
  <pre><code>Connect success
  Doc inserted
  Connect success
  Doc inserted
  Connect success
  com.mongodb.MongoTimeoutException: Timed out after 10000 ms while waiting for a server that matches AnyServerSelector{}. Client view of cluster state is {type=Unknown, servers=[{address=127.0.0.1:27017, type=Unknown, state=Connecting, exception={com.mongodb.MongoException$Network: Exception opening the socket}, caused by {java.net.SocketException: Too many open files}}]
      at com.mongodb.BaseCluster.getServer(BaseCluster.java:82)
      at com.mongodb.DBTCPConnector.getServer(DBTCPConnector.java:654)
      at com.mongodb.DBTCPConnector.access$300(DBTCPConnector.java:39)
      at com.mongodb.DBTCPConnector$MyPort.getConnection(DBTCPConnector.java:503)
      at com.mongodb.DBTCPConnector$MyPort.get(DBTCPConnector.java:451)
      at com.mongodb.DBTCPConnector.authenticate(DBTCPConnector.java:624)
      at com.mongodb.DBApiLayer.doAuthenticate(DBApiLayer.java:195)
      at com.mongodb.DB.authenticateCommandHelper(DB.java:765)
      at com.mongodb.DB.authenticate(DB.java:721)
      at UdpGPSListener.main(UdpGPSListener.java:108)
  </code></pre>
  
  <p>and below is my code in Java :</p>
  
  <pre><code>            DatagramSocket serverSocket = new DatagramSocket(2020);
          byte[] receiveData = new byte[2048];
          DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
          serverSocket.receive(receivePacket);
          String dtCollection = new String(receivePacket.getData(), "UTF8");
          String[] arrCollection = dtCollection.split(",");
          String dtField = "UnitTime,Ab1,ab2,ab3,ab4,ab5,ab6,ab7,cc1,cc2,cc3,cc4,cc5,cc6,cc7,cc8,cc9,cc9,cc10,m01,m02,m03,m04,m05,m06,m07";
          String[] arrField = dtField.split(",");
          String gbCollection="";
          for (int m=0; m&lt;arrCollection.length; m++) {
              gbCollection+=arrField[m] + "=" +arrCollection[m] +",";
          }
              try {
                  MongoClient mClient = new MongoClient();
                  //MongoClient mClient = new MongoClient("127.0.0.1", 27017);
                  DB db = mClient.getDB("mms");
                          System.out.println("Connect success");
                  boolean auth = db.authenticate("user1", "passw0rd".toCharArray());
                  DBCollection coll = db.getCollection("tgps");
                  BasicDBObject doc = new BasicDBObject(arrField[0], arrCollection[0]).
                      append(arrField[1], arrCollection[1]).
                      append(arrField[2], arrCollection[2]).
                      append(arrField[3], arrCollection[3]).
                      append(arrField[4], arrCollection[4]).
                      append(arrField[5], arrCollection[5]).
                      append(arrField[6], arrCollection[6]).
                      append(arrField[7], arrCollection[7]).
                      append(arrField[8], arrCollection[8]).
                      append(arrField[9], arrCollection[9]).
                      append(arrField[10], arrCollection[10]).
                      append(arrField[11], arrCollection[11]).
                      append(arrField[12], arrCollection[12]).
                      append(arrField[13], arrCollection[13]).
                      append(arrField[14], arrCollection[14]).
                      append(arrField[15], arrCollection[15]).
                      append(arrField[16], arrCollection[16]).
                      append(arrField[17], arrCollection[17]).
                      append(arrField[18], arrCollection[18]).
                      append(arrField[19], arrCollection[19]).
                      append(arrField[20], arrCollection[20]).
                      append(arrField[21], arrCollection[21]).
                      append(arrField[22], arrCollection[22]).
                      append(arrField[23], arrCollection[23]).
                      append(arrField[24], arrCollection[24]).
                      append(arrField[25], new Date());
                  coll.insert(doc);
                  System.out.println("Doc inserted");
              } catch(UnknownHostException  e) {
                      System.err.println(e.getClass().getName() + ": " + e.getMessage() );
              } catch(MongoException e) {
                      e.printStackTrace();
              }
  </code></pre>