win8.1安装mongodb

在windows8.1 环境下 安装 mongodb,下载版本:mongodb-win32-x86_64-2008plus-ssl-3.2.5-signed.msi


1、在mongodb官网下载如下文件并运行

mongodb-win32-x86_64-2008plus-ssl-3.2.5-signed.msi

2、启动mongodb,运行mongod.exe,看到如下部分说明安装成功了

2016-05-11T23:35:01.107+0800 I NETWORK  [initandlisten] waiting for connections
on port 27017

测试以下,可以正常访问,localhost:27017

页面返回内容如下:

It looks like you are trying to access MongoDB over HTTP on the native driver port.


3、连接mongodb

找到mongo.exe,并运行,如下,并输入db为test的对象mydata,x=1


C:\Program Files\MongoDB\Server\3.2\bin>mongo.exe
MongoDB shell version: 3.2.5
connecting to: test
Server has startup warnings:
2016-05-09T00:38:36.299+0800 I CONTROL  [initandlisten]
2016-05-09T00:38:36.300+0800 I CONTROL  [initandlisten] ** WARNING: Insecure con
figuration, access control is not enabled and no --bind_ip has been specified.
2016-05-09T00:38:36.301+0800 I CONTROL  [initandlisten] **          Read and wri
te access to data and configuration is unrestricted,
2016-05-09T00:38:36.301+0800 I CONTROL  [initandlisten] **          and the serv
er listens on all available network interfaces.
2016-05-09T00:38:36.302+0800 I CONTROL  [initandlisten]

> db.test.save({int:1})
WriteResult({ "nInserted" : 1 })
> db.test.find()
{ "_id" : ObjectId("572f6f86506112939377d8b6"), "int" : 1 }
> exit()
2016-05-11T23:26:17.158+0800 E QUERY    [thread1] ReferenceError: exit is not de
fined :
@(shell):1:1


> exit
bye


以下操作是为系统自动配置mongodb,避免每次登陆后需要重新开启mongodb的麻烦。

4、为windows配置mongodb

由于以上步骤每次启动时都手动输入命令启动,过于繁琐,因此,配置使其自动启动


注:将mongo.exe运行窗口关闭,否则如下连接运行时会报错,如下:

2016-05-11T23:31:25.885+0800 E NETWORK  [initandlisten] listen(): bind() failed
errno:10048 通常每个套接字地址(协议/网络地址/端口)只允许使用一次。 for socket: 0
.0.0.0:27017
2016-05-11T23:31:25.886+0800 E STORAGE  [initandlisten] Failed to set up sockets
 during startup.
2016-05-11T23:31:25.886+0800 I CONTROL  [initandlisten] dbexit:  rc: 48



创建配置文件

monogod.cfg文件内容如下:

##日志文件
systemLog:
    destination: file    ##注意此处4个空格,不要使用tab
    path: C:\Program Files\MongoDB\Server\3.2\data\log\mongod.log  ##注意此处4个空格,不要使用tab
 
##数据文件
storage:
    dbPath: C:\Program Files\MongoDB\Server\3.2\data\db  ##注意此处4个空格,不要使用tab


执行如下:

C:\Program Files\MongoDB\Server\3.2\bin>mongod.exe -config "C:\Program Files\Mon
goDB\Server\3.2\mongod.cfg"
2016-05-11T23:59:40.657+0800 I CONTROL  [main] log file "C:\Program Files\MongoD
B\Server\3.2\data\log\mongod.log" exists; moved to "C:\Program Files\MongoDB\Ser
ver\3.2\data\log\mongod.log.2016-05-11T15-59-40".


C:\Program Files\MongoDB\Server\3.2\bin>net start mongodb


MongoDB 服务已经启动成功。



后续如果要重启,则直接在服务中重启即可!

你可能感兴趣的:(mongodb)