`

MongoDB安装说明

阅读更多

下载介绍

MONGODB的官网:http://www.mongodb.org/

MONGODB的下载:http://www.mongodb.org/download/

MONGODB的java驱动:https://github.com/mongodb/mongo-java-driver/downloads

MONGODB针对java的api文档:http://api.mongodb.org/java/2.6.2/

 

安装说明

Linux/Unix/OS X

1、建立数据目录
 mkdir -p /data/db
2、下载压缩包
 curl -O http://downloads.mongodb.org/linux/mongodb-linux-i686-latest.tgz

或下载安装包后上传至服务器

3、解压缩文件
 tar xzf mongodb-linux-i386-latest.tgz
4、启动服务
 bin/mongod run &
5、使用自带客户端连接
 /bin/mongo
6、测试
 db.foo.save( { a : 1 } )
 db.foo.findOne()

 

基本命令

1、启动命令

<!--[if !supportLists]-->Ø <!--[endif]-->mongod 启动数据库进程

<!--[if !supportLists]-->Ø <!--[endif]-->--dbpath 指定数据库的目录

<!--[if !supportLists]-->Ø <!--[endif]-->--port 指定数据库的端口,默认是27017

<!--[if !supportLists]-->Ø <!--[endif]-->--bind_ip 绑定IP

<!--[if !supportLists]-->Ø <!--[endif]-->--directoryperdb为每个db创建一个独立子目录

<!--[if !supportLists]-->Ø <!--[endif]-->--logpath指定日志存放目录

<!--[if !supportLists]-->Ø <!--[endif]-->--logappend指定日志生成方式(追加/覆盖)

<!--[if !supportLists]-->Ø <!--[endif]-->例如:mongod --dbpath db --port 27098--directoryperdb --logpath db\logs\mongodb.log logappend 

 

2、停止服务

关闭数据有两种方式:

<!--[if !supportLists]-->Ø <!--[endif]--><1>在窗口模式中,可以直接使用Ctrl+C停止服务

<!--[if !supportLists]-->Ø <!--[endif]--><2>通过mongo连接至客户端,并使用db.shutdownServer()停止服务。

 

3、其它命令

<!--[if !supportLists]-->Ø <!--[endif]-->show dbs // 列出所有数据库

<!--[if !supportLists]-->Ø <!--[endif]-->use test // 使用数据库test ,即使这个数据库不存在也可以执行,但该数据库不会立刻被新建,要等到执行了insert之类的操作时,才会建立这个数据库

<!--[if !supportLists]-->Ø <!--[endif]-->show collections // 列出当前数据库的所有文档

<!--[if !supportLists]-->Ø <!--[endif]-->db // 显示当前数据库

<!--[if !supportLists]-->Ø <!--[endif]-->show users // 列出用户

 

4、帮助命令

<!--[if !supportLists]-->Ø <!--[endif]-->想知道mongodb支持哪些命令,可以直接输入help、如果想知道当前数据库支持哪些方法,可以使用db.help()命令、如果想知道当前数据库下的表或者表collection支持哪些方法,可以使用命令db.dbname.help()。

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics