异常com.mongodb.MongoException: not talking to master and retries used up 处理办法

在关于mogodb的测试代码:

 

package com.test;

import java.net.UnknownHostException;

import com.mongodb.DB;
import com.mongodb.Mongo;
import com.mongodb.MongoException;

public class TestDB {

 public static String mongoStatServer = "192.168.0.1";
 public static int mongoStatPort = 12345;

 /**
  * @param args
  */
 public static void main(String[] args) {

  Mongo mongo = null;
  try {
   mongo = new Mongo(mongoStatServer, mongoStatPort);
   DB db = mongo.getDB("testdb");
   //db.slaveOk();
   System.out.println(db.getName()+"--"+db.getCollectionNames());
  
  } catch (UnknownHostException e) {
   e.printStackTrace();
  } catch (MongoException e) {
   e.printStackTrace();
  }

 }

}

会出现如下异常:

com.mongodb.MongoException: not talking to master and retries used up
 at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:245)
 at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:247)
 at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:247)
 at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:313)
 at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:298)
 at com.mongodb.DB.getCollectionNames(DB.java:298)
 at com.test.TestDB.main(TestDB.java:24)

 

 

加上    db.slaveOk();  就正常了.

 

比较奇怪的问题,.这里记录一下.

你可能感兴趣的:(mongodb,Java技术,错误处理)