记录一下mongoDB的使用

忽然打算进军node.js的开发领域,并且以此为工作,于是一不小心boss上投了几份简历,竟然恰好有公司回应,遂打算去试试,于是乎详细的介绍了我前端的本质,以及进军后端的决心,因为我想去试试呀,所以一不小心吹了小牛说自己可以三天拿下mongoDB,虽然事实是我其实今天上午之前对他还没有足够的了解,甚至从未接触过任何一款数据库产品,怎样呢,吹出去的牛就是熬着夜通着宵也要把他实现,这池子水不知是深是浅,感兴趣的小朋友可以跟我一起试试。下面我会尽可能详细的介绍学习mongo的全过程。
没带我的mac本子 所以暂时以Windows为例

安装

  • 大家可以根据自己的电脑型号自行下载
    https://www.mongodb.com/downl…

  • 创建数据目录
    在任意的一个盘新建一个空目录,我创建在了C盘里 但并不建议哈,我只是想快速的走一下过场。如 C:/data/db (这个就是你的dbpath)

c:\>mkdir data

c:\>cd data

c:\data>mkdir db

c:\data>cd db
  • 运行mongoDB服务
    找到mongodb安装目录,如果是自定义安装的是 C:/Program Files/MongoDB/Server/3.4bin
    在bin文件运行

bin文件里边一般用到的就两个文件

mongod.exe用来启动mongodb服务(启动之后你的数据库就可以使用了的意思)

mongo.exe用来启动进入数据库(然后你就可以命令操作数据库的意思)
mongod --dbpath=刚创建的空目录,如
mongod --dbpath=C:\data\db
2017-09-01T00:55:51.350-0700 I CONTROL  [initandlisten] MongoDB starting : pid=31752 port=27017 dbpath=c:\data\db 64-bit host=A001823-PC02
2017-09-01T00:55:51.350-0700 I CONTROL  [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2
2017-09-01T00:55:51.351-0700 I CONTROL  [initandlisten] db version v3.4.7
2017-09-01T00:55:51.351-0700 I CONTROL  [initandlisten] git version: cf38c1b8a0a8dca4a11737581beafef4fe120bcd
2017-09-01T00:55:51.352-0700 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.1u-fips  22 Sep 2016
2017-09-01T00:55:51.352-0700 I CONTROL  [initandlisten] allocator: tcmalloc
2017-09-01T00:55:51.352-0700 I CONTROL  [initandlisten] modules: none
2017-09-01T00:55:51.353-0700 I CONTROL  [initandlisten] build environment:
2017-09-01T00:55:51.353-0700 I CONTROL  [initandlisten]     distmod: 2008plus-ssl
2017-09-01T00:55:51.353-0700 I CONTROL  [initandlisten]     distarch: x86_64
2017-09-01T00:55:51.354-0700 I CONTROL  [initandlisten]     target_arch: x86_64
2017-09-01T00:55:51.354-0700 I CONTROL  [initandlisten] options: { storage: { dbPath: "c:\data\db" } }
2017-09-01T00:55:51.371-0700 I -        [initandlisten] Detected data files in c:\data\db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2017-09-01T00:55:51.372-0700 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=3534M,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-09-01T00:55:52.349-0700 I CONTROL  [initandlisten]
2017-09-01T00:55:52.349-0700 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-09-01T00:55:52.350-0700 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2017-09-01T00:55:52.350-0700 I CONTROL  [initandlisten]
2017-09-01T15:55:52.594+0800 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory 'c:/data/db/diagnostic.data'
2017-09-01T15:55:52.596+0800 I NETWORK  [thread1] waiting for connections on port 27017
2017-09-01T16:14:55.905+0800 I CONTROL  [thread2] Ctrl-C signal
2017-09-01T16:14:55.905+0800 I CONTROL  [consoleTerminate] got CTRL_C_EVENT, will terminate after current cmd ends
2017-09-01T16:14:55.906+0800 I NETWORK  [consoleTerminate] shutdown: going to close listening sockets...
2017-09-01T16:14:55.906+0800 I NETWORK  [consoleTerminate] closing listening socket: 480
2017-09-01T16:14:55.907+0800 I NETWORK  [consoleTerminate] shutdown: going to flush diaglog...
2017-09-01T16:14:55.907+0800 I FTDC     [consoleTerminate] Shutting down full-time diagnostic data capture
2017-09-01T16:14:55.914+0800 I STORAGE  [consoleTerminate] WiredTigerKVEngine shutting down
2017-09-01T16:14:56.173+0800 I STORAGE  [consoleTerminate] shutdown: removing fs lock...
2017-09-01T16:14:56.173+0800 I CONTROL  [consoleTerminate] now exiting
2017-09-01T16:14:56.174+0800 I CONTROL  [consoleTerminate] shutting down with code:12

看到这个基本就是启动成功并且坚挺了27017的端口waiting for connections on port 27017

这就挺好的可以参考
http://www.cnblogs.com/imwtr/…

    原文作者:小小年128
    原文地址: https://segmentfault.com/a/1190000010980014
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞