Mongodb错误,第一次安装没有经验

  1. 云栖社区>
  2. 博客>
  3. 正文

Mongodb错误,第一次安装没有经验

e生态 2012-03-13 10:36:00 浏览1299
展开阅读全文
代码
package com.yansl;

import java.net.UnknownHostException;

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

public class MongodbTest {

private Mongo mong=null;

private DB db=null;

private DBCollection dbc=null;

public MongodbTest()
{
try {
mong=new Mongo();
System.out.println(mong);
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MongoException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
db=mong.getDB("MyTest");
System.out.println(db);

dbc=db.getCollection("table1");
System.out.println(dbc);
}

public void selectAll(){
System.out.println("查询table1中的所有数据:");

//得到查询
DBCursor cur = dbc.find();

//遍历结果
while(cur.hasNext()){
System.out.println(cur.next());
}
}

public static void main(String[] args) {
MongodbTest m=new MongodbTest();
m.selectAll();
}

}

输出和错误信息
————————————————————————————————————————————————

Mongo: 127.0.0.1:27017
MyTest
table1
查询table1中的所有数据:
2012-3-12 17:47:21 com.mongodb.DBTCPConnector fetchMaxBsonObjectSize
警告: null
java.io.IOException: couldn't connect to [/127.0.0.1:27017] bc:java.net.ConnectException: Connection refused: connect
at com.mongodb.DBPort._open(DBPort.java:206)
at com.mongodb.DBPort.go(DBPort.java:94)
at com.mongodb.DBPort.go(DBPort.java:75)
at com.mongodb.DBPort.findOne(DBPort.java:129)
at com.mongodb.DBPort.runCommand(DBPort.java:138)
at com.mongodb.DBTCPConnector.fetchMaxBsonObjectSize(DBTCPConnector.java:409)
at com.mongodb.DBTCPConnector.checkMaster(DBTCPConnector.java:396)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:192)
at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:295)
at com.mongodb.DBCursor._check(DBCursor.java:354)
at com.mongodb.DBCursor._hasNext(DBCursor.java:484)
at com.mongodb.DBCursor.hasNext(DBCursor.java:509)
at com.yansl.MongodbTest.selectAll(MongodbTest.java:45)
at com.yansl.MongodbTest.main(MongodbTest.java:52)
2012-3-12 17:47:23 com.mongodb.DBTCPConnector$MyPort error
严重: MyPort.error called
java.io.IOException: couldn't connect to [/127.0.0.1:27017] bc:java.net.ConnectException: Connection refused: connect
at com.mongodb.DBPort._open(DBPort.java:206)
at com.mongodb.DBPort.go(DBPort.java:94)
at com.mongodb.DBPort.go(DBPort.java:75)
at com.mongodb.DBPort.call(DBPort.java:65)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:201)
at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:295)
at com.mongodb.DBCursor._check(DBCursor.java:354)
at com.mongodb.DBCursor._hasNext(DBCursor.java:484)
at com.mongodb.DBCursor.hasNext(DBCursor.java:509)
at com.yansl.MongodbTest.selectAll(MongodbTest.java:45)
at com.yansl.MongodbTest.main(MongodbTest.java:52)
2012-3-12 17:47:24 com.mongodb.DBTCPConnector fetchMaxBsonObjectSize
警告: null
java.io.IOException: couldn't connect to [/127.0.0.1:27017] bc:java.net.ConnectException: Connection refused: connect
at com.mongodb.DBPort._open(DBPort.java:206)
at com.mongodb.DBPort.go(DBPort.java:94)
at com.mongodb.DBPort.go(DBPort.java:75)
at com.mongodb.DBPort.findOne(DBPort.java:129)
at com.mongodb.DBPort.runCommand(DBPort.java:138)
at com.mongodb.DBTCPConnector.fetchMaxBsonObjectSize(DBTCPConnector.java:409)
at com.mongodb.DBTCPConnector.checkMaster(DBTCPConnector.java:396)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:192)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:220)
at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:295)
at com.mongodb.DBCursor._check(DBCursor.java:354)
at com.mongodb.DBCursor._hasNext(DBCursor.java:484)
at com.mongodb.DBCursor.hasNext(DBCursor.java:509)
at com.yansl.MongodbTest.selectAll(MongodbTest.java:45)
at com.yansl.MongodbTest.main(MongodbTest.java:52)
2012-3-12 17:47:25 com.mongodb.DBTCPConnector$MyPort error
严重: MyPort.error called
java.io.IOException: couldn't connect to [/127.0.0.1:27017] bc:java.net.ConnectException: Connection refused: connect
at com.mongodb.DBPort._open(DBPort.java:206)
at com.mongodb.DBPort.go(DBPort.java:94)
at com.mongodb.DBPort.go(DBPort.java:75)
at com.mongodb.DBPort.call(DBPort.java:65)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:201)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:220)
at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:295)
at com.mongodb.DBCursor._check(DBCursor.java:354)
at com.mongodb.DBCursor._hasNext(DBCursor.java:484)
at com.mongodb.DBCursor.hasNext(DBCursor.java:509)
at com.yansl.MongodbTest.selectAll(MongodbTest.java:45)
at com.yansl.MongodbTest.main(MongodbTest.java:52)
2012-3-12 17:47:26 com.mongodb.DBTCPConnector fetchMaxBsonObjectSize
警告: null
java.io.IOException: couldn't connect to [/127.0.0.1:27017] bc:java.net.ConnectException: Connection refused: connect
at com.mongodb.DBPort._open(DBPort.java:206)
at com.mongodb.DBPort.go(DBPort.java:94)
at com.mongodb.DBPort.go(DBPort.java:75)
at com.mongodb.DBPort.findOne(DBPort.java:129)
at com.mongodb.DBPort.runCommand(DBPort.java:138)
at com.mongodb.DBTCPConnector.fetchMaxBsonObjectSize(DBTCPConnector.java:409)
at com.mongodb.DBTCPConnector.checkMaster(DBTCPConnector.java:396)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:192)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:220)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:220)
at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:295)
at com.mongodb.DBCursor._check(DBCursor.java:354)
at com.mongodb.DBCursor._hasNext(DBCursor.java:484)
at com.mongodb.DBCursor.hasNext(DBCursor.java:509)
at com.yansl.MongodbTest.selectAll(MongodbTest.java:45)
at com.yansl.MongodbTest.main(MongodbTest.java:52)
2012-3-12 17:47:27 com.mongodb.DBTCPConnector$MyPort error
严重: MyPort.error called
java.io.IOException: couldn't connect to [/127.0.0.1:27017] bc:java.net.ConnectException: Connection refused: connect
at com.mongodb.DBPort._open(DBPort.java:206)
at com.mongodb.DBPort.go(DBPort.java:94)
at com.mongodb.DBPort.go(DBPort.java:75)
at com.mongodb.DBPort.call(DBPort.java:65)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:201)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:220)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:220)
at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:295)
at com.mongodb.DBCursor._check(DBCursor.java:354)
at com.mongodb.DBCursor._hasNext(DBCursor.java:484)
at com.mongodb.DBCursor.hasNext(DBCursor.java:509)
at com.yansl.MongodbTest.selectAll(MongodbTest.java:45)
at com.yansl.MongodbTest.main(MongodbTest.java:52)
Exception in thread "main" com.mongodb.MongoException$Network: can't call something
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:209)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:220)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:220)
at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:295)
at com.mongodb.DBCursor._check(DBCursor.java:354)
at com.mongodb.DBCursor._hasNext(DBCursor.java:484)
at com.mongodb.DBCursor.hasNext(DBCursor.java:509)
at com.yansl.MongodbTest.selectAll(MongodbTest.java:45)
at com.yansl.MongodbTest.main(MongodbTest.java:52)
Caused by: java.io.IOException: couldn't connect to [/127.0.0.1:27017] bc:java.net.ConnectException: Connection refused: connect
at com.mongodb.DBPort._open(DBPort.java:206)
at com.mongodb.DBPort.go(DBPort.java:94)
at com.mongodb.DBPort.go(DBPort.java:75)
at com.mongodb.DBPort.call(DBPort.java:65)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:201)
... 8 more

网友评论

登录后评论
0/500
评论