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

本文涉及的产品
云数据库 MongoDB,独享型 2核8GB
推荐场景:
构建全方位客户视图
简介: 代码 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
代码
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
相关实践学习
MongoDB数据库入门
MongoDB数据库入门实验。
快速掌握 MongoDB 数据库
本课程主要讲解MongoDB数据库的基本知识,包括MongoDB数据库的安装、配置、服务的启动、数据的CRUD操作函数使用、MongoDB索引的使用(唯一索引、地理索引、过期索引、全文索引等)、MapReduce操作实现、用户管理、Java对MongoDB的操作支持(基于2.x驱动与3.x驱动的完全讲解)。 通过学习此课程,读者将具备MongoDB数据库的开发能力,并且能够使用MongoDB进行项目开发。   相关的阿里云产品:云数据库 MongoDB版 云数据库MongoDB版支持ReplicaSet和Sharding两种部署架构,具备安全审计,时间点备份等多项企业能力。在互联网、物联网、游戏、金融等领域被广泛采用。 云数据库MongoDB版(ApsaraDB for MongoDB)完全兼容MongoDB协议,基于飞天分布式系统和高可靠存储引擎,提供多节点高可用架构、弹性扩容、容灾、备份回滚、性能优化等解决方案。 产品详情: https://www.aliyun.com/product/mongodb
目录
相关文章
|
4月前
|
NoSQL MongoDB Python
【Python】已完美解决(MongoDB安装报错)Service ‘MongoDB Server (MongoDB)’ (MongoDB) failed tostart
【Python】已完美解决(MongoDB安装报错)Service ‘MongoDB Server (MongoDB)’ (MongoDB) failed tostart
292 1
|
1月前
|
NoSQL Ubuntu Linux
Linux平台安装MongoDB
10月更文挑战第11天
43 5
|
1月前
|
NoSQL Shell MongoDB
Mac OSX 平台安装 MongoDB
10月更文挑战第11天
21 4
|
16天前
|
存储 NoSQL 网络协议
【赵渝强老师】MongoDB的安装与访问
本文介绍了在Linux系统上安装和部署MongoDB的详细步骤,包括安装依赖包、解压安装包、配置环境变量、创建数据目录及启动服务等。文中还提供了相关命令示例和注意事项,帮助用户顺利完成MongoDB的安装与配置。
|
1月前
|
NoSQL Shell MongoDB
Windows 平台安装 MongoDB
10月更文挑战第10天
46 0
Windows 平台安装 MongoDB
|
1月前
|
存储 NoSQL MongoDB
docker安装Mongodb
这篇文章详细说明了如何使用Docker安装MongoDB,包括拉取镜像、创建并运行容器、数据持久化存储以及访问容器内的MongoDB服务的具体步骤。
135 1
|
5月前
|
NoSQL 前端开发 MongoDB
[保姆级教程]Windows安装MongoDB教程
【6月更文挑战第4天】该内容是关于MongoDB的安装包下载及安装步骤指南。首先,访问网址 <a href="https://www.mongodb.com/try" target="_blank">https://www.mongodb.com/try</a> 进入官网,选择MongoDB Community Edition(社区版)。接着,挑选合适的版本和系统平台,推荐下载zip压缩包。下载后,进行安装,依次点击“Next”同意协议,选择自定义安装路径,然后继续安装直至完成。
629 0
|
3月前
|
JavaScript NoSQL 前端开发
|
3月前
|
NoSQL Ubuntu MongoDB
在Ubuntu 16.04上安装和保护MongoDB的方法
在Ubuntu 16.04上安装和保护MongoDB的方法
36 1
|
3月前
|
NoSQL 安全 MongoDB
用python安装mongodb
用python安装mongodb
28 0
下一篇
无影云桌面