程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MongoDB數據庫 >> MongoDB綜合知識 >> MongoDB最基本命令速查筆記

MongoDB最基本命令速查筆記

編輯:MongoDB綜合知識

安裝後在控制台輸入:

mongo啟動客戶端。

show dbs顯示所有數據庫。

use xxx選中數據庫為當前使用的數據庫。

show collections顯示當前數據庫的所有集合。

db.colleciton.find()來查找表格的所有數據。

db.serverStatus()查看數據庫服務器的狀態。

db.stats()查詢指定數據庫的統計信息。

use xxx如果數據庫不存在則創建數據庫(必須在雖然插入一條數據)

db.storeCollection.insert({'version':'13', 'segment':'456'})插入數據,同時創建集合

db.dropDatabase()刪除數據庫

db.mycoll.drop()刪除集合

db.storeCollection.save({'version':'3.5', 'segment':'e3ol6'})更新記錄

db.storeCollection.remove({'version':'3.5'}) 刪除記錄

db.page.ensureIndex({'title':1, 'url':-1})創建索引,1正序,-1逆序

db.page.getIndexes()查詢建立的索引

db.mycoll.dropIndex(name) 刪除索引,如果不帶參數,刪除所有索引

db.baseSe.reIndex()重建索引

db.baseSe.storageSize()查詢指定數據庫的集合的可用的存儲空間

db.baseSe.totalSize()查詢集合已分配的存儲空間

PS:非正常關閉後無法啟動問題
段時間不小心非正常關閉了mongoDB,准備重啟卻發現不行,錯誤信息如下:

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

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved