windows下安裝mongodb和簡單使用mongodb命令
一。下載,解壓文件
到官方下載合適的版本 http://www.mongodb.org/downloads
例如:http://fastdl.mongodb.org/win32/mongodb-win32-i386-1.6.5.zip
解壓後放到對應的盤符下面,例如:G:\mongodb165
二。安裝
1.把bin目錄加入到環境變量中 G:\mongodb165\bin
2.在G:\mongodb165下建立data文件夾放數據用
3.簡單啓動mongodb方法:
進入到bin目錄下
C:\Documents and Settings\zheng>G:
G:\>cd mongodb165/bin
G:\mongodb165\bin>mongod --dbpath G:/mongodb165/data
G:\mongodb165\bin>mongod --dbpath G:/mongodb165/data
Sun Jan 16 14:56:03 MongoDB starting : pid=860 port=27017 dbpath=G:/mongodb165/d
ata 32-bitmysql
** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of datagit
** see http://blog.mongodb.org/post/137788967/32-bit-limitationsweb
Sun Jan 16 14:56:03 db version v1.6.5, pdfile version 4.5
Sun Jan 16 14:56:03 git version: 0eb017e9b2828155a67c5612183337b89e12e291
Sun Jan 16 14:56:03 sys info: windows (5, 1, 2600, 2, 'Service Pack 3') BOOST_LI
B_VERSION=1_35
Sun Jan 16 14:56:03 [initandlisten] waiting for connections on port 27017
Sun Jan 16 14:56:03 [websvr] web admin interface listening on port 28017sql
注:必須先創建data文件夾和到bin目錄下執行。mongoDB 服務端的默認鏈接端口是 27017mongodb
2.添加到註冊表做爲Windows服務啓動,和mysql同樣啓動Windows時會自動啓動服務,到bin目錄下執行
G:\mongodb165\bin>mongod --logpath G:\mongodb165\logs\mongodb165.log --logappend
--dbpath G:\mongodb165\data --directoryperdb --serviceName mongodb165 --installshell
完成後輸出下面內容(360等殺毒軟件會阻止,須要容許經過)
all output going to: G:\mongodb165\logs\mongodb165.log
Creating service mongodb165.
Service creation successful.
Service can be started from the command line via 'net start "mongodb165"'.數據庫
G:\mongodb165\bin>windows
其中:logs\mongodb165.log日誌是以追加的方式輸出的,--serviceName mongodb165是服務名稱
啓動MongoDB:net start mongodb165
中止MongoDB:net stop mongodb165
注:添加到註冊表後重啓電腦在服務項裏面能夠看到已經啓動,但服務仍然沒有啓動,重啓服務發現給360安全衛士阻止了須要再次肯定才能啓動。安全
3.mongodb的簡單使用命令,到bin命令下執行mongo.exe進入管理界面,默認是進入到test賬號。
G:\mongodb165\bin>mongo.exe
MongoDB shell version: 1.6.5
connecting to: test
> show dbs;
admin
local
> help;查看命令提示
db.help() help on db methods
db.mycoll.help() help on collection methods
rs.help() help on replica set methods
help connect connecting to a db help
help admin administrative help
help misc misc things to knowapp
show dbs show database names show collections show collections in current database show users show users in current database show profile show most recent system.profile entries wit h time >= 1ms use <db_name> set current database db.foo.find() list objects in collection foo db.foo.find( { a : 1 } ) list objects in foo where a == 1 it result of the last line evaluated; use to f urther iterate exit quit the mongo shell > use testdb;切換到testdb數據庫,若是不存在則在插入數據後會自動建立一個,在data目錄下能夠看到新增了一個testdb的文件夾 switched to db testdb > db.myc.save({a:10});向collection mpc 中保存一條信息,若是不存在collection會自動建立一個 > db.myc.find();檢索全部記錄 { "_id" : ObjectId("4d32c9204e6100000000691e"), "a" : 10 } > show collections; myc system.indexes >exit;退出