【软件安装】MongoDB 下载

MongoDB 提供了可用于 32 位和 64 位系统的预编译二进制包,你可以从MongoDB官网下载安装,MongoDB 预编译二进制包下载地址:https://www.mongodb.com/download-center#community

注意:在 MongoDB 2.2 版本后已经不再支持 Windows XP 系统。最新版本也已经没有了 32 位系统的安装文件。

  • MongoDB for Windows 64-bit 适合 64 位的 Windows Server 2008 R2, Windows 7 , 及最新版本的 Window 系统。
  • MongoDB for Windows 32-bit 适合 32 位的 Window 系统及最新的 Windows Vista。 32 位系统上 MongoDB 的数据库最大为 2GB。
  • MongoDB for Windows 64-bit Legacy 适合 64 位的 Windows Vista, Windows Server 2003, 及 Windows Server 2008 。

根据你的系统下载 32 位或 64 位的 .msi 文件,下载后双击该文件,按操作提示安装即可。

安装过程中,你可以通过点击 "Custom(自定义)" 按钮来设置你的安装目录。

创建数据目录

MongoDB将数据目录存储在 db 目录下。但是这个数据目录不会主动创建,我们在安装完成后需要创建它。请注意,数据目录应该放在根目录下((如: C:\ 或者 D:\ 等 )。

在本教程中,我们已经在C:盘 安装了 mongodb,现在让我们创建一个data的目录然后在data目录里创建db目录。

C:\Users\licl11092>cd d:
D:\

C:\Users\licl11092>d:

D:\>mkdir data

D:\>cd data

D:\data>mkdir db

D:\data>cd db

你也可以通过window的资源管理器中创建这些目录,而不一定通过命令行。


命令行下运行 MongoDB 服务器

为了从命令提示符下运行 MongoDB 服务器,必须从切换到MongoDB 目录的 bin 目录下:D:\data\db>cd D:\mongoDb\Server\bin。

mongod --dbpath d:\data\db

如果执行成功,会输出如下信息:

D:\mongoDb\Server\bin>mongod --dbpath d:\data\db
2017-08-30T09:59:42.665+0800 I CONTROL  [initandlisten] MongoDB starting : pid=9176 port=27017 dbpath=d:\data\db 64-bit host=DESKTOP-Q3LQVJD
2017-08-30T09:59:42.665+0800 I CONTROL  [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2
2017-08-30T09:59:42.666+0800 I CONTROL  [initandlisten] db version v3.4.4
2017-08-30T09:59:42.667+0800 I CONTROL  [initandlisten] git version: 888390515874a9debd1b6c5d36559ca86b44babd
2017-08-30T09:59:42.667+0800 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.1u-fips  22 Sep 2016
2017-08-30T09:59:42.667+0800 I CONTROL  [initandlisten] allocator: tcmalloc
2017-08-30T09:59:42.668+0800 I CONTROL  [initandlisten] modules: none
2017-08-30T09:59:42.668+0800 I CONTROL  [initandlisten] build environment:
2017-08-30T09:59:42.668+0800 I CONTROL  [initandlisten]     distmod: 2008plus-ssl
2017-08-30T09:59:42.669+0800 I CONTROL  [initandlisten]     distarch: x86_64
2017-08-30T09:59:42.669+0800 I CONTROL  [initandlisten]     target_arch: x86_64
2017-08-30T09:59:42.670+0800 I CONTROL  [initandlisten] options: { storage: { dbPath: "d:\data\db" } }
2017-08-30T09:59:42.672+0800 I -        [initandlisten] Detected data files in d:\data\db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2017-08-30T09:59:42.672+0800 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=7634M,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,log_size=2GB),statistics_log=(wait=0),
2017-08-30T09:59:43.063+0800 I CONTROL  [initandlisten]
2017-08-30T09:59:43.063+0800 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-08-30T09:59:43.063+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2017-08-30T09:59:43.064+0800 I CONTROL  [initandlisten]
2017-08-30T09:59:43.162+0800 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory 'd:/data/db/diagnostic.data'
2017-08-30T09:59:43.163+0800 I NETWORK  [thread1] waiting for connections on port 27017

mongodb默认连接端口27017,如果出现如图的情况,可以打开http://localhost:27017查看(笔者这里是chrome),发现如图则表示连接成功,如果不成功,可以查看端口是否被占用。

c:\foo>"c:\Program Files\MongoDB\Server\3.2\bin\mongo.exe"
MongoDB shell version: 3.2.5
connecting to: test
2016-04-26T13:41:31.032+0100 W NETWORK  [thread1] Failed to connect to 127.0.0.1
:27017, reason: errno:10061 No connection could be made because the target machine actively refused it.
2016-04-26T13:41:31.034+0100 E QUERY    [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:229:14
@(connect):1:6

exception: connect failed

c:\foo>ver

Microsoft Windows [Version 6.3.9600]

 解决方法:

First, you should install Mongodb as a service,

  • Open your cmd as admin
  • Run ( net start mongodb )
  • Now you can run the command ( mongo ) and you will be able to connect normally, with no Problem.
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

路途…

点滴记录

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值