安裝后在控制臺(tái)輸入:
mongo啟動(dòng)客戶端。
show dbs顯示所有數(shù)據(jù)庫。
use xxx選中數(shù)據(jù)庫為當(dāng)前使用的數(shù)據(jù)庫。
show collections顯示當(dāng)前數(shù)據(jù)庫的所有集合。
db.colleciton.find()來查找表格的所有數(shù)據(jù)。
db.serverStatus()查看數(shù)據(jù)庫服務(wù)器的狀態(tài)。
db.stats()查詢指定數(shù)據(jù)庫的統(tǒng)計(jì)信息。
use xxx如果數(shù)據(jù)庫不存在則創(chuàng)建數(shù)據(jù)庫(必須在雖然插入一條數(shù)據(jù))
db.storeCollection.insert({'version':'13', 'segment':'456'})插入數(shù)據(jù),同時(shí)創(chuàng)建集合
db.dropDatabase()刪除數(shù)據(jù)庫
db.mycoll.drop()刪除集合
db.storeCollection.save({'version':'3.5', 'segment':'e3ol6'})更新記錄
db.storeCollection.remove({'version':'3.5'}) 刪除記錄
db.page.ensureIndex({'title':1, 'url':-1})創(chuàng)建索引,1正序,-1逆序
db.page.getIndexes()查詢建立的索引
db.mycoll.dropIndex(name) 刪除索引,如果不帶參數(shù),刪除所有索引
db.baseSe.reIndex()重建索引
db.baseSe.storageSize()查詢指定數(shù)據(jù)庫的集合的可用的存儲(chǔ)空間
db.baseSe.totalSize()查詢集合已分配的存儲(chǔ)空間
PS:非正常關(guān)閉后無法啟動(dòng)問題
段時(shí)間不小心非正常關(guān)閉了mongoDB,準(zhǔn)備重啟卻發(fā)現(xiàn)不行,錯(cuò)誤信息如下:
Tue Apr 17 11:13:30Tue Apr 17 11:13:30 warning: 32-bit servers don't have journaling enabled by default. Please use --journal if you want durability.Tue Apr 17 11:13:30Tue Apr 17 11:13:30 [initandlisten] MongoDB starting : pid=7128 port=27017 dbpath=D:/Programs/mongodb204/db 32-bit host=FALCONTue Apr 17 11:13:30 [initandlisten]Tue Apr 17 11:13:30 [initandlisten] ** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of dataTue Apr 17 11:13:30 [initandlisten] ** see http://blog.mongodb.org/post/137788967/32-bit-limitationsTue Apr 17 11:13:30 [initandlisten] ** with --journal, the limit is lowerTue Apr 17 11:13:30 [initandlisten]Tue Apr 17 11:13:30 [initandlisten] db version v2.0.4, pdfile version 4.5Tue Apr 17 11:13:30 [initandlisten] git version: 329f3c47fe8136c03392c8f0e548506cb21f8ebfTue Apr 17 11:13:30 [initandlisten] build info: windows sys.getwindowsversion(major=6, minor=0, build=6002, platform=2, service_pack='Service Pack 2')BOOST_LIB_VERSION=1_42Tue Apr 17 11:13:30 [initandlisten] options: { dbpath: "D:/Programs/mongodb204/db" }**************Unclean shutdown detected.Please visit http://dochub.mongodb.org/core/repair for recovery instructions.*************Tue Apr 17 11:13:30 [initandlisten] exception in initAndListen: 12596 old lock file, terminatingTue Apr 17 11:13:30 dbexit:Tue Apr 17 11:13:30 [initandlisten] shutdown: going to close listening sockets...Tue Apr 17 11:13:30 [initandlisten] shutdown: going to flush diaglog...Tue Apr 17 11:13:30 [initandlisten] shutdown: going to close sockets...Tue Apr 17 11:13:30 [initandlisten] shutdown: waiting for fs preallocator...Tue Apr 17 11:13:30 [initandlisten] shutdown: closing all files...Tue Apr 17 11:13:30 [initandlisten] closeAllFiles() finishedTue Apr 17 11:13:30 dbexit: really exiting now
解決方法:
1、刪除%MONGO_HOME%/db下的.lock文件
2、輸入命令 mongod --repair
3、重啟mongoDB