安裝后在控制臺(tái)輸入:
mongo啟動(dòng)客戶端。
show dbs顯示所有數(shù)據(jù)庫(kù)。
use xxx選中數(shù)據(jù)庫(kù)為當(dāng)前使用的數(shù)據(jù)庫(kù)。
show collections顯示當(dāng)前數(shù)據(jù)庫(kù)的所有集合。
db.colleciton.find()來(lái)查找表格的所有數(shù)據(jù)。
db.serverStatus()查看數(shù)據(jù)庫(kù)服務(wù)器的狀態(tài)。
db.stats()查詢指定數(shù)據(jù)庫(kù)的統(tǒng)計(jì)信息。
use xxx如果數(shù)據(jù)庫(kù)不存在則創(chuàng)建數(shù)據(jù)庫(kù)(必須在雖然插入一條數(shù)據(jù))
db.storeCollection.insert({'version':'13', 'segment':'456'})插入數(shù)據(jù),同時(shí)創(chuàng)建集合
db.dropDatabase()刪除數(shù)據(jù)庫(kù)
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ù)庫(kù)的集合的可用的存儲(chǔ)空間
db.baseSe.totalSize()查詢集合已分配的存儲(chǔ)空間
PS:非正常關(guān)閉后無(wú)法啟動(dòng)問(wèn)題
段時(shí)間不小心非正常關(guān)閉了mongoDB,準(zhǔn)備重啟卻發(fā)現(xiàn)不行,錯(cuò)誤信息如下:
Tue Apr 17 11:13:30
Tue 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:30
Tue Apr 17 11:13:30 [initandlisten] MongoDB starting : pid=7128 port=27017 dbpath=D:\Programs\mongodb204\db 32-bit host=FALCON
Tue 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 data
Tue Apr 17 11:13:30 [initandlisten] ** see http://blog.mongodb.org/post/137788967/32-bit-limitations
Tue Apr 17 11:13:30 [initandlisten] ** with --journal, the limit is lower
Tue Apr 17 11:13:30 [initandlisten]
Tue Apr 17 11:13:30 [initandlisten] db version v2.0.4, pdfile version 4.5
Tue Apr 17 11:13:30 [initandlisten] git version: 329f3c47fe8136c03392c8f0e548506cb21f8ebf
Tue 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_42
Tue 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, terminating
Tue 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() finished
Tue Apr 17 11:13:30 dbexit: really exiting now
解決方法:
1、刪除%MONGO_HOME%/db下的.lock文件
2、輸入命令 mongod --repair
3、重啟mongoDB
您可能感興趣的文章:- MongoDB常用操作命令大全
- mongodb與mysql命令詳細(xì)對(duì)比
- MongoDB常用命令小結(jié)
- Ubuntu系統(tǒng)中安裝MongoDB及其啟動(dòng)命令mongod的教程
- MongoDB入門教程(包含安裝、常用命令、相關(guān)概念、使用技巧、常見(jiàn)操作等)
- MongoDB使用mongoexport和mongoimport命令,批量導(dǎo)出和導(dǎo)入JSON數(shù)據(jù)到同一張表的實(shí)例
- Mongodb啟動(dòng)命令參數(shù)中文說(shuō)明
- mongodb數(shù)據(jù)庫(kù)的6個(gè)安全設(shè)置命令
- mongodb 命令行下及php中insert數(shù)據(jù)詳解
- 詳解MongoDB管理命令
- Ubuntu下安裝PHP的mongodb擴(kuò)展操作命令
- MongoDB中的主從同步配置和mongod相關(guān)啟動(dòng)命令講解
- MongoDB使用自帶的命令行工具進(jìn)行備份和恢復(fù)的教程
- MongoDB Shell 命令實(shí)例總結(jié)【進(jìn)階篇】
- Mongodb 啟動(dòng)命令mongod參數(shù)說(shuō)明(中文翻譯)
- mongodb監(jiān)控工具mongostat的使用及命令詳解
- MongoDB的基本安裝與管理命令腳本總結(jié)
- MongoDB常用數(shù)據(jù)庫(kù)命令大全