如果想查看當(dāng)前連接在哪個(gè)數(shù)據(jù)庫(kù)下面,可以直接輸入db
目前創(chuàng)新互聯(lián)公司已為1000多家的企業(yè)提供了網(wǎng)站建設(shè)、域名、網(wǎng)站空間、網(wǎng)站改版維護(hù)、企業(yè)網(wǎng)站設(shè)計(jì)、尼瑪網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長(zhǎng),共同發(fā)展。
> db
Admin
想切換到test數(shù)據(jù)庫(kù)下面
> 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.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
如果想知道當(dāng)前數(shù)據(jù)庫(kù)支持哪些方法:
> db.help();
DB methods:
db.addUser(username, password) 添加數(shù)據(jù)庫(kù)授權(quán)用戶
db.auth(username, password) 訪問(wèn)認(rèn)證
db.cloneDatabase(fromhost) 克隆數(shù)據(jù)庫(kù)
db.commandHelp(name) returns the help for the command
db.copyDatabase(fromdb, todb, fromhost) 復(fù)制數(shù)據(jù)庫(kù)
db.createCollection(name, { size : ..., capped : ..., max : ... } ) 創(chuàng)建表
db.currentOp() displays the current operation in the db
db.dropDatabase() 刪除當(dāng)前數(shù)據(jù)庫(kù)
db.eval_r(func, args) run code server-side
db.getCollection(cname) same as db['cname'] or db.cname
db.getCollectionNames() 獲取當(dāng)前數(shù)據(jù)庫(kù)的表名
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ù)庫(kù)的復(fù)制狀態(tài)信息
db.printSlaveReplicationInfo() 打印從數(shù)據(jù)庫(kù)的復(fù)制狀態(tài)信息
db.printShardingStatus() 打印分片狀態(tài)信息
db.removeUser(username) 刪除數(shù)據(jù)庫(kù)用戶
db.repairDatabase() 修復(fù)數(shù)據(jù)庫(kù)
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