我正在尝试从部署在 JBOSS 中的应用程序写入 mongodb,这就是我得到的,我需要在 mongodb 中做些什么吗?这似乎是论坛讨论的并发问题。
14:00:07,083 WARNING [com.mongodb.tcp] (Camel (camel-2) thread #3 - JmsConsumer[barTopic]) Exception executing isMaster command on /127.0.0.1:27017: java.lang.NullPointerException
at com.mongodb.DBPort._open(DBPort.java:203) [mongo-java-driver-2.9.1.jar:]
at com.mongodb.DBPort.go(DBPort.java:107) [mongo-java-driver-2.9.1.jar:]
at com.mongodb.DBPort.go(DBPort.java:88) [mongo-java-driver-2.9.1.jar:]
at com.mongodb.DBPort.findOne(DBPort.java:143) [mongo-java-driver-2.9.1.jar:]
at com.mongodb.DBPort.runCommand(DBPort.java:148) [mongo-java-driver-2.9.1.jar:]
at com.mongodb.DBTCPConnector.initDirectConnection(DBTCPConnector.java:539) [mongo-java-driver-2.9.1.jar:]
at com.mongodb.Mongo.getMaxBsonObjectSize(Mongo.java:600) [mongo-java-driver-2.9.1.jar:]
at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:233) [mongo-java-driver-2.9.1.jar:]
at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:205) [mongo-java-driver-2.9.1.jar:]
at com.mongodb.DBCollection.insert(DBCollection.java:57) [mongo-java-driver-2.9.1.jar:]
at com.mongodb.DBCollection.insert(DBCollection.java:100) [mongo-java-driver-2.9.1.jar:]
at com.magick.magicktrader.BarServiceBean.addBarToMongoDB(BarServiceBean.java:196) [magicktrader.jar:0.6.0-SNAPSHOT]
at com.magick.magicktrader.BarServiceBean.getBar(BarServiceBean.java:40) [magicktrader.jar:0.6.0-SNAPSHOT]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.6.0_10]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [rt.jar:1.6.0_10]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [rt.jar:1.6.0_10]
at java.lang.reflect.Method.invoke(Method.java:597) [rt.jar:1.6.0_10]
方法调用
MongoURI uri = null;
uri = new MongoURI("mongodb://localhost:27017");
try{
mongo = new Mongo(uri);
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//prop.getProperty("database")
db = mongo.getDB("charts");
db.requestStart();
//prop.getProperty("collection")
dbCollection = db.getCollection("bars");
/**
* Bar Structure - attributes
*
* symbol,low,high
* open,close,time
* volume;
**/
for (Bar bar : barList) {
document = new BasicDBObject();
document.put("symbol", bar.getSymbol());
document.put("low", bar.getLow());
document.put("high", bar.getHigh());
document.put("open", bar.getOpen());
document.put("close", bar.getClose());
document.put("time", bar.getTime());
document.put("volume", bar.getVolume());
//dbCollection.insert(document);
//prop.getProperty("collection").trim()
dbCollection.getCollection("bars");
dbCollection.save(document, WriteConcern.NORMAL);
}