1.下载对应的版本:http://www.mongodb.org/downloads
我这里下载的是“mongodb-win32-x86_64-2.2.3”
2.安装
2.1 解压到任意目录。我这里是C:\mongodb-win32-x86_64-2.2.3。此时该目录下有bin文件夹。
2.2 mongodb需要db目录(存放数据),log目录(存放日志)的。手动创建data,db,log文件夹
-
在mongodb2.0目录下建立data文件夹。
-
在data文件夹建立db文件夹
-
在data文件夹下建立log文件夹,并在log文件夹下建立mongodb.log文件
2.3 准备工作到位,现在开始安装
打开doc窗口。
进入到mongodb-win32-x86_64-2.2.3\bin目录
执行::C:\mongodb-win32-x86_64-2.2.3\bin>mongod -dbpath "C:\mongodb-win32-x86_64-2.2.3\data\db",出现下面的打印,并且会持续很久!:
- Tue Mar 05 11:49:37 [initandlisten] waiting for connections on port 27017
Tue Mar 05 11:49:37 [initandlisten] waiting for connections on port 27017
注意了!!!!!!!
当看到这行“waiting for connections on port 27017”时,到浏览器中输入地址“localhost:27017”,回车!
浏览器会打印:
You are trying to access MongoDB on the native driver port. For http diagnostic access, add 1000 to the port number。
此时回到doc窗口。可以看到了“admin web console waiting for connections on port 28017 ”。
再回到浏览器。输入“localhost:28017”,回车。
看到如下信息,说明MongoDB已经启动成功了。
- mongod E72C413811423E
- List all commands | Replica set status
- Commands: buildInfo cursorInfo features hostInfo isMaster listDatabases replSetGetStatus serverStatus top
- db version v2.2.3, pdfile version 4.5
- git hash: f570771a5d8a3846eb7586eaffcf4c2f4a96bf08
- sys info: windows sys.getwindowsversion(major=6, minor=1, build=7601, platform=2, service_pack='Service Pack 1') BOOST_LIB_VERSION=1_49
- uptime: 3932 seconds
- overview (only reported if can acquire read lock quickly)
- time to get readlock: 0ms
- # databases: 1
- # Cursors: 0
- replication:
- master: 0
- slave: 0
mongod E72C413811423E
List all commands | Replica set status
Commands: buildInfo cursorInfo features hostInfo isMaster listDatabases replSetGetStatus serverStatus top
db version v2.2.3, pdfile version 4.5
git hash: f570771a5d8a3846eb7586eaffcf4c2f4a96bf08
sys info: windows sys.getwindowsversion(major=6, minor=1, build=7601, platform=2, service_pack='Service Pack 1') BOOST_LIB_VERSION=1_49
uptime: 3932 seconds
overview (only reported if can acquire read lock quickly)
time to get readlock: 0ms
# databases: 1
# Cursors: 0
replication:
master: 0
slave: 0
测试与使用:
新打开一个DOS窗口,win+R, cmd,回车。
进入到C:\mongodb-win32-x86_64-2.2.3\bin目录,执行命令“C:\mongodb-win32-x86_64-2.2.3\bin>mongo”,
- C:\mongodb-win32-x86_64-2.2.3\bin>mongo
- MongoDB shell version: 2.2.3
- connecting to: test
- Welcome to the MongoDB shell.
- For interactive help, type "help".
- For more comprehensive documentation, see
- http://docs.mongodb.org/
- Questions? Try the support group
- http://groups.google.com/group/mongodb-user
- > db.foo.insert({a:123,b:345})
- > db.foo.find()
- { "_id" : ObjectId("51357b2003004382ccd87dcd"), "a" : 123, "b" : 345 }
- >
C:\mongodb-win32-x86_64-2.2.3\bin>mongo
MongoDB shell version: 2.2.3
connecting to: test
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
http://docs.mongodb.org/
Questions? Try the support group
http://groups.google.com/group/mongodb-user
> db.foo.insert({a:123,b:345})
> db.foo.find()
{ "_id" : ObjectId("51357b2003004382ccd87dcd"), "a" : 123, "b" : 345 }
>
test是默认数据库,foo是默认表。简单的插入,查询。
- > db.foo.insert({a:123,b:345})
- > db.foo.find()
- { "_id" : ObjectId("51357b2003004382ccd87dcd"), "a" : 123, "b" : 345 }
- >
> db.foo.insert({a:123,b:345})
> db.foo.find()
{ "_id" : ObjectId("51357b2003004382ccd87dcd"), "a" : 123, "b" : 345 }
>
3.为了我们使用方便,我们把mongo注册成服务。这样可以通过控制面板-管理工具-服务来启动和关闭mongo了。
同样的,进入到d:\mongodb2.0\bin目录。
执行命令:
C:\mongodb-win32-x86_64-2.2.3\bin>mongod -dbpath "C:\mongodb-win32-x86_64-2.2.3\data\db" --logpath "C:\mongodb-win32-x86_64-2.2.3\data\log\mongodb.log" --install --serviceName "MongoDB" \\回车
到服务里看看吧,