db Admin 想切換到test數(shù)據(jù)庫下面 > use test switched to db test > db Test想查看test下有哪..."/>
溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

MongoDB 常用的命令

發(fā)布時間:2020-06-21 15:48:25 來源:網(wǎng)絡 閱讀:314 作者:冷暖己知 欄目:數(shù)據(jù)庫

如果想查看當前連接在哪個數(shù)據(jù)庫下面,可以直接輸入db

> db
Admin

想切換到test數(shù)據(jù)庫下面

> use test
switched to db test
> db

Test想查看test下有哪些表或者叫collection,可以輸入

> show collections

system.indexes

user想知道mongodb支持哪些命令,可以直接輸入help

 

 

> help
HELP
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 with time >= 1ms
use <db name>  set curent database to <db name>
db.help()  help on DB methods
db.foo.help()  help on collection methods
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 further iterate

如果想知道當前數(shù)據(jù)庫支持哪些方法:

> db.help();
DB methods:
db.addUser(username, password) 添加數(shù)據(jù)庫授權用戶
db.auth(username, password)  訪問認證
db.cloneDatabase(fromhost) 克隆數(shù)據(jù)庫
db.commandHelp(name) returns the help for the command
db.copyDatabase(fromdb, todb, fromhost)  復制數(shù)據(jù)庫
db.createCollection(name, { size : ..., capped : ..., max : ... } ) 創(chuàng)建表
db.currentOp() displays the current operation in the db
db.dropDatabase()  刪除當前數(shù)據(jù)庫
db.eval_r(func, args) run code server-side
db.getCollection(cname) same as db['cname'] or db.cname
db.getCollectionNames()  獲取當前數(shù)據(jù)庫的表名
db.getLastError() - just returns the err msg string
db.getLastErrorObj() - return full status object
db.getMongo() get the server connection object
db.getMongo().setSlaveOk() allow this connection to read from the nonmaster member of a replica pair
db.getName()
db.getPrevError()
db.getProfilingLevel()
db.getReplicationInfo()
db.getSisterDB(name) get the db at the same server as this onew
db.killOp() kills the current operation in the db
db.printCollectionStats()  打印各表的狀態(tài)信息
db.printReplicationInfo()  打印主數(shù)據(jù)庫的復制狀態(tài)信息
db.printSlaveReplicationInfo()  打印從數(shù)據(jù)庫的復制狀態(tài)信息
db.printShardingStatus()  打印分片狀態(tài)信息
db.removeUser(username) 刪除數(shù)據(jù)庫用戶
db.repairDatabase() 修復數(shù)據(jù)庫
db.resetError()
db.runCommand(cmdObj) run a database command.  if cmdObj is a string, turns it into { cmdObj : 1 }
db.setProfilingLevel(level) 0=off 1=slow 2=all
db.shutdownServer()
db.version() current version of the server


向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內容。

AI