日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mongodb 存储过程 遍历表数据_mongodb查看数据库和表的信息

發布時間:2025/3/15 数据库 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mongodb 存储过程 遍历表数据_mongodb查看数据库和表的信息 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

mongodb查看數據庫和表的方法比較簡單,在為這里推薦使用stats的方法,直觀并且詳細。

1、查看數據庫

db.stats();

1

輸出:

{

"db" : "sirius",

"collections" : 3,

"objects" : 5,

"avgObjSize" : 55.2,

"dataSize" : 276,

"storageSize" : 16384,

"numExtents" : 3,

"indexes" : 1,

"indexSize" : 8176,

"fileSize" : 50331648,

"nsSizeMB" : 16,

"ok" : 1

}

2、查看數據庫表

db.sirius.stats();

1

輸出:

{

"ns" : "sirius.sirius",

"size" : 84,

"count" : 2,

"avgObjSize" : 42,

"storageSize" : 36864,

"capped" : false,

"wiredTiger" : {...},

"nindexes" : 1,

"totalIndexSize" : 36864,

"indexSizes" : {

"_id_" : 36864

},

"ok" : 1

}

3、db的幫助文檔

db.help();

1

輸出:

db.adminCommand(nameOrDocument)// 切換到'admin'數據庫,并且運行命令

db.AddUser(username,password[, readOnly=false]) //添加用戶

db.auth(usrename,password) // 設置數據庫連接驗證

db.cloneDataBase(fromhost) // 從目標服務器克隆一個數據庫

db.commandHelp(name) // returns the help for the command

db.copyDatabase(fromdb,todb,fromhost) // 復制數據庫fromdb---源數據庫名稱,todb---目標數據庫名稱,fromhost---源數據庫服務器地址

db.createCollection(name,{size:3333,capped:333,max:88888}) // 創建一個數據集,相當于一個表

db.createView(name, viewOn, [ { $operator: {...}}, ... ], { viewOptions } ) // 創建視圖

db.createUser(userDocument) // 創建用戶

db.currentOp() // 取消當前庫的當前操作

db.dropDataBase() // 刪除當前數據庫

db.eval(func,args) // (已過時) run code server-side

db.fsyncLock() // 將數據保存到硬盤并且鎖定服務器備份

db.fsyncUnlock() unlocks server following a db.fsyncLock()

db.getCollection(cname) // 取得一個數據集合,同用法:db['cname'] or db.cname

db.getCollenctionNames() // 取得所有數據集合的名稱列表

db.getLastError() // 返回最后一個錯誤的提示消息

db.getLastErrorObj() // 返回最后一個錯誤的對象

db.getLogComponents()

db.getMongo() // 取得當前服務器的連接對象get the server

db.getMondo().setSlaveOk() // allow this connection to read from then nonmaster membr of a replica pair

db.getName() // 返回當操作數據庫的名稱

db.getPrevError() // 返回上一個錯誤對象

db.getProfilingLevel() // 獲取profile level

db.getReplicationInfo() // 獲得重復的數據

db.getSisterDB(name) // get the db at the same server as this onew

db.killOp() // 停止(殺死)在當前庫的當前操作

db.listCommands() // lists all the db commands

db.loadServerScripts() // loads all the scripts in db.system.js

db.logout()

db.printCollectionStats() // 返回當前庫的數據集狀態

db.printReplicationInfo() // 打印主數據庫的復制狀態信息

db.printSlaveReplicationInfo() // 打印從數據庫的復制狀態信息

db.printShardingStatus() // 返回當前數據庫是否為共享數據庫

db.removeUser(username) // 刪除用戶

db.repairDatabase() // 修復當前數據庫

db.resetError()

db.runCommand(cmdObj) // run a database command. if cmdObj is a string, turns it into {cmdObj:1}

db.runCommand(cmdObj) // run a database command. if cmdObj is a string, turns it into { cmdObj : 1 }

db.serverStatus()

db.setLogLevel(level, )

db.setProfilingLevel(level, ) // 設置profile level 0=off,1=slow,2=all

db.setWriteConcern( ) // sets the write concern for writes to the db

db.unsetWriteConcern( ) // unsets the write concern for writes to the db

db.setVerboseShell(flag) // display extra information in shell output

db.shutdownServer() // 關閉當前服務程序

db.stats() // 返回當前數據庫的狀態信息

db.version() // 返回當前程序的版本信息

4、表的幫助

db.tableName.help();

1

輸出:

db.test.find({id:10}) // 返回test數據集ID=10的數據集

db.test.find({id:10}).count() // 返回test數據集ID=10的數據總數

db.test.find({id:10}).limit(2) // 返回test數據集ID=10的數據集從第二條開始的數據集

db.test.find({id:10}).skip(8) // 返回test數據集ID=10的數據集從0到第八條的數據集

db.test.find({id:10}).limit(2).skip(8) // 返回test數據集ID=1=的數據集從第二條到第八條的數據

db.test.find({id:10}).sort() // 返回test數據集ID=10的排序數據集

db.test.findOne([query]) // 返回符合條件的一條數據

db.test.getDB() // 返回此數據集所屬的數據庫名稱

db.test.getIndexes() // 返回些數據集的索引信息

db.test.group({key:...,initial:...,reduce:...[,cond:...]}) // 返回分組信息

db.test.mapReduce(mayFunction,reduceFunction,) // 這個有點像存儲過程

db.test.remove(query) // 在數據集中刪除一條數據

db.test.renameCollection(newName) // 重命名些數據集名稱

db.test.save(obj) // 往數據集中插入一條數據

db.test.stats() // 返回此數據集的狀態

db.test.storageSize() // 返回此數據集的存儲大小

db.test.totalIndexSize() // 返回此數據集的索引文件大小

db.test.totalSize() // 返回些數據集的總大小

db.test.update(query,object[,upsert_bool]) // 在此數據集中更新一條數據

db.test.validate() // 驗證此數據集

db.test.getShardVersion() // 返回數據集共享版本號

---------------------

總結

以上是生活随笔為你收集整理的mongodb 存储过程 遍历表数据_mongodb查看数据库和表的信息的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。