Mongodb的windows下免安装

正常途径访问Mongodb的官方网站,它只提供了msi 安装包的下载,这种方式带来的好处是直接作为windows的服务进行管理。

但是在有些情况下,我们希望不作为windows的服务进行安装,比如受到公司IT 安全策略的限制,管理员权限不会提供给我们,那么在这种情况下,我们希望能够通过免安装的方式使用mongodb。

操作方法:

1, 访问mongodb官方网站提供的文件列表

https://www.mongodb.org/dl/win32

2, 此列表提供了很多的windows版本,其中还包括是否支持ssl的版本,根据自己的需要选择对应的版本下载,并解压到希望的目录

3, 设置mongodb的数据存放目录,比如D:\tryout\mongodb\data

4, 启动mongodb服务:

进入 cmd提示符控制台, 执行$mongodb\bin\mongod.exe --dbpath=D:\tryout\mongodb\data

如果成功,会提示如下类似如下信息:

2017-05-23T17:05:52.814+0800 I CONTROL  [initandlisten] MongoDB starting : pid=9
368 port=27017 dbpath=d:\tryout\mongodb\data 64-bit host=SSC1-W440
2017-05-23T17:05:52.815+0800 I CONTROL  [initandlisten] targetMinOS: Windows Vis
ta/Windows Server 2008
2017-05-23T17:05:52.815+0800 I CONTROL  [initandlisten] db version v3.4.5-rc1
2017-05-23T17:05:52.815+0800 I CONTROL  [initandlisten] git version: a3874e7dfb6
e3012098c843a1cd05735ee36aab3
2017-05-23T17:05:52.816+0800 I CONTROL  [initandlisten] allocator: tcmalloc
2017-05-23T17:05:52.816+0800 I CONTROL  [initandlisten] modules: none
2017-05-23T17:05:52.817+0800 I CONTROL  [initandlisten] build environment:
2017-05-23T17:05:52.817+0800 I CONTROL  [initandlisten]     distarch: x86_64
2017-05-23T17:05:52.817+0800 I CONTROL  [initandlisten]     target_arch: x86_64
2017-05-23T17:05:52.818+0800 I CONTROL  [initandlisten] options: { storage: { db
Path: "d:\tryout\mongodb\data" } }
2017-05-23T17:05:52.819+0800 I -        [initandlisten] Detected data files in d
:\tryout\mongodb\data created by the 'wiredTiger' storage engine, so setting the
 active storage engine to 'wiredTiger'.
2017-05-23T17:05:52.819+0800 I STORAGE  [initandlisten] wiredtiger_open config:
create,cache_size=3427M,session_max=20000,eviction=(threads_min=4,threads_max=4)
,config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal
,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,lo
g_size=2GB),statistics_log=(wait=0),
2017-05-23T17:05:53.497+0800 I CONTROL  [initandlisten]
2017-05-23T17:05:53.498+0800 I CONTROL  [initandlisten] ** WARNING: Access contr
ol is not enabled for the database.
2017-05-23T17:05:53.498+0800 I CONTROL  [initandlisten] **          Read and wri
te access to data and configuration is unrestricted.
2017-05-23T17:05:53.499+0800 I CONTROL  [initandlisten]
2017-05-23T17:05:53.499+0800 I CONTROL  [initandlisten] Hotfix KB2731284 or late
r update is not installed, will zero-out data files.
2017-05-23T17:05:53.500+0800 I CONTROL  [initandlisten]
2017-05-23T17:05:54.608+0800 I FTDC     [initandlisten] Initializing full-time d
iagnostic data capture with directory 'd:/tryout/mongodb/data/diagnostic.data'
2017-05-23T17:05:54.610+0800 I NETWORK  [thread1] waiting for connections on por
t 27017
2017-05-23T17:05:54.782+0800 I NETWORK  [thread1] connection accepted from 127.0
.0.1:58806 #1 (1 connection now open)

 

5,使用客户端连接mongodb的数据库

再另开一个cmd窗口,执行$mongodb\bin\mongo.exe

如果连接成功,会提示类似如下信息:

$ ./mongo.exe
MongoDB shell version v3.4.5-rc1
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.5-rc1

6,默认的数据库是test,在代码中可以通过如下的URI访问 mongodb://localhost:27017/test

posted @ 2017-05-23 17:10  自由协会会长  阅读(5030)  评论(0编辑  收藏  举报