ITeye博客

Windows平台下安装MongoDB

cakin24 · 2017-07-25 21:56 · MongoDB · 编程语言 · Windows · MongoDB · 安装 · Markdown

一 MongoDB下载

1、到MongoDB官网下载安装包。

2、MongoDB官网下载地址:https://www.mongodb.com/download-center#community

3、笔者下载的版本是:mongodb-win32-x86_64-2008plus-ssl-3.2.10-signed.msi

4、下载后双击该文件,按操作提示安装即可。

笔者安装路径为:D:\MongoDB

5、在path环境变量中加入:D:\MongoDB\Server\3.2\bin

 

二 创建数据目录

D:\data\db

 

三 命令行下运行 MongoDB 服务器

mongod.exe --dbpath d:\data\db

启动成功则提示如下:

2017-06-08T20:46:13.306+0800 I CONTROL  [initandlisten] MongoDB starting : pid=204948 port=27017 dbpath=d:\data\db 64-bit host=DESKTOP-MNG19L3

2017-06-08T20:46:13.309+0800 I CONTROL  [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2

2017-06-08T20:46:13.310+0800 I CONTROL  [initandlisten] db version v3.2.10

2017-06-08T20:46:13.310+0800 I CONTROL  [initandlisten] git version: 79d9b3ab5ce20f51c272b4411202710a082d0317

2017-06-08T20:46:13.310+0800 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.1t-fips  3 May 2016

2017-06-08T20:46:13.311+0800 I CONTROL  [initandlisten] allocator: tcmalloc

2017-06-08T20:46:13.311+0800 I CONTROL  [initandlisten] modules: none

2017-06-08T20:46:13.311+0800 I CONTROL  [initandlisten] build environment:

2017-06-08T20:46:13.311+0800 I CONTROL  [initandlisten]     distmod: 2008plus-ssl

2017-06-08T20:46:13.311+0800 I CONTROL  [initandlisten]     distarch: x86_64

2017-06-08T20:46:13.311+0800 I CONTROL  [initandlisten]     target_arch: x86_64

2017-06-08T20:46:13.311+0800 I CONTROL  [initandlisten] options: { storage: { dbPath: "d:\data\db" } }

2017-06-08T20:46:13.315+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-06-08T20:46:13.316+0800 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=1G,session_max=20000,eviction=(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-06-08T20:46:15.185+0800 I NETWORK  [HostnameCanonicalizationWorker] Starting hostname canonicalization worker

2017-06-08T20:46:15.185+0800 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory 'd:/data/db/diagnostic.data'

2017-06-08T20:46:15.202+0800 I NETWORK  [initandlisten] waiting for connections on port 27017

 

四 连接MongoDB数据库

mongo -u <user> -p <pass> --host <host> --port 28015

例如:

C:\Users\lenovo>mongo --host 127.0.0.1 --port 27017

MongoDB shell version: 3.2.10

connecting to: 127.0.0.1:27017/test

五 MongoDB后台管理 Shell

1、当你进入mongoDB后台后,它默认会链接到 test 文档(数据库)

C:\Users\lenovo>mongo

MongoDB shell version: 3.2.10

connecting to: test

2、由于它是一个JavaScript shell,您可以运行一些简单的算术运算

> 2+2

4

3、db命令用于查看当前操作的文档(数据库)

> db

test

4、插入一些简单的记录并查找它:

> db.runoob.insert({x:10})

WriteResult({ "nInserted" : 1 })

> db.runoob.find()

{ "_id" : ObjectId("5939485fae09c56bd9c1d374"), "x" : 10 }

>

以上第一个命令将数字 10 插入到 runoob 集合的 x 字段中。

5、打开或创建文档(数据库)students

> use students

switched to db students

6、向students集合(表)中插入一条记录并查找它。

> zhangsan={'name':'zhangsan','age':18,'sex':'male'}

{ "name" : "zhangsan", "age" : 18, "sex" : "male" }

> db.students.insert(zhangsan)

WriteResult({ "nInserted" : 1 })

> db.students.find()

{ "_id" : ObjectId("59394a87ae09c56bd9c1d375"), "name" : "zhangsan", "age" : 18, "sex" : "male" }

7、向当前系统查询所有文档(数据库)

> show dbs

local     0.000GB

students  0.000GB

test      0.000GB

>

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。