MongoDB初學

參考:MongoDB 教程 | 菜鳥教程java

安裝

1.下載安裝,從官網下載winows安裝包,安裝到d盤(注意路徑)git

2.因爲我安裝在d盤,因此在d盤建立文件夾data,裏面建立db文件夾數據庫

3.啓動方法:在D:\Program Files\MongoDB\Server\3.2\bin下雙擊mongod.exe,以下則顯示正常:session

2016-04-15T21:24:08.293+0800 I CONTROL  [initandlisten] MongoDB starting : pid=6276 port=27017 dbpath=D:\data\db\ 64-bit host=DESKTOP-LPJTSPF
2016-04-15T21:24:08.295+0800 I CONTROL  [initandlisten] targetMinOS: Windows Vista/Windows Server 2008
2016-04-15T21:24:08.295+0800 I CONTROL  [initandlisten] db version v3.2.5
2016-04-15T21:24:08.296+0800 I CONTROL  [initandlisten] git version: 34e65e5383f7ea1726332cb175b73077ec4a1b02
2016-04-15T21:24:08.296+0800 I CONTROL  [initandlisten] allocator: tcmalloc
2016-04-15T21:24:08.296+0800 I CONTROL  [initandlisten] modules: none
2016-04-15T21:24:08.296+0800 I CONTROL  [initandlisten] build environment:
2016-04-15T21:24:08.297+0800 I CONTROL  [initandlisten]     distarch: x86_64
2016-04-15T21:24:08.297+0800 I CONTROL  [initandlisten]     target_arch: x86_64
2016-04-15T21:24:08.297+0800 I CONTROL  [initandlisten] options: {}
2016-04-15T21:24:08.297+0800 I -        [initandlisten] Detected data files in D:\data\db\ created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2016-04-15T21:24:08.298+0800 W -        [initandlisten] Detected unclean shutdown - D:\data\db\mongod.lock is not empty.
2016-04-15T21:24:08.298+0800 W STORAGE  [initandlisten] Recovering data from the last clean checkpoint.
2016-04-15T21:24:08.299+0800 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=4G,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),
2016-04-15T21:24:08.464+0800 I CONTROL  [initandlisten]
2016-04-15T21:24:08.465+0800 I CONTROL  [initandlisten] ** WARNING: Insecure configuration, access control is not enabled and no --bind_ip has been specified.
2016-04-15T21:24:08.465+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted,
2016-04-15T21:24:08.465+0800 I CONTROL  [initandlisten] **          and the server listens on all available network interfaces.
2016-04-15T21:24:08.465+0800 I CONTROL  [initandlisten]
2016-04-15T21:24:08.467+0800 I NETWORK  [HostnameCanonicalizationWorker] Starting hostname canonicalization worker
2016-04-15T21:24:08.467+0800 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory 'D:/data/db/diagnostic.data'
2016-04-15T21:24:08.468+0800 I NETWORK  [initandlisten] waiting for connections on port 27017
2016-04-15T21:24:09.023+0800 I FTDC     [ftdc] Unclean full-time diagnostic data capture shutdown detected, found interim file, some metrics may have been lost. OK
2016-04-15T21:24:19.975+0800 I NETWORK  [initandlisten] connection accepted from 127.0.0.1:13732 #1 (1 connection now open)

若一閃而過則由於默認在d盤下的data/db文件夾未找到。若是你不想將db放在d:/data/db下也能夠指定db位置:app

cmd 進入d盤,cd Program Files\MongoDB\Server\3.2\bin,mongod.exe dbpath 指定的位置測試

這樣也能夠開啓數據庫。ui

4.打開客戶端。雙擊bin目錄下的mongo.exe,若不閃退則啓動成功。url

5.測試:rest

> db
test
> 1+2
3
> db.runoob.insert({x:10})
WriteResult({ "nInserted" : 1 })
> db.runoob.find()
{ "_id" : ObjectId("5710e88c34bf37767b29a10e"), "x" : 10 }
相關文章
相關標籤/搜索