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, <component>)
db.setProfilingLevel(level, <slowms>) // 设置profile level 0=off,1=slow,2=all
db.setWriteConcern( <write concern doc> ) // sets the write concern for writes to the db
db.unsetWriteConcern( <write concern doc> ) // 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,<optional params>) // 这个有点像存储过程
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查看数据库和表的信息的更多相关文章
- SQL Server 游标运用:查看数据库所有表大小信息
一.本文所涉及的内容(Contents) 本文所涉及的内容(Contents) 背景(Contexts) 实现代码(SQL Codes) 方法一:运用游标 方法二:运用系统存储过程 方法三:拼接SQL ...
- mongodb 查看数据库和表大小
1.查看数据库 > db.stats(); { "db" : "test", //当前数据库 "collections" : 3, / ...
- SQL Server 游标运用:查看所有数据库所有表大小信息(Sizes of All Tables in All Database)
原文:SQL Server 游标运用:查看所有数据库所有表大小信息(Sizes of All Tables in All Database) 一.本文所涉及的内容(Contents) 本文所涉及的内容 ...
- SQL Server 游标运用:查看一个数据库所有表大小信息(Sizes of All Tables in a Database)
原文:SQL Server 游标运用:查看一个数据库所有表大小信息(Sizes of All Tables in a Database) 一.本文所涉及的内容(Contents) 本文所涉及的内容(C ...
- mysql查看数据库和表的占用空间大小
mysql查看数据库和表的占用空间大小 第一部分-任务 将线上db,导出后,导入到office db 一. 两种方案: 1,将数据直接从online-->office,通过mysqldump ...
- SQL中查看数据库各表的大小
SQL中查看数据库各表的大小 编写人:CC阿爸 2014-6-17 在日常SQL数据库的操作中,如何快速的查询数据库中各表中数据的大小. 以下有两种方法供参考: 第一种: create table # ...
- mysql 查看数据库、表的基本命令
1:show databases; 查看所有的数据库,等同于select schema_name from information_schema.schemata\G.\G 替换;,以纵向报表的形式输 ...
- SQL Server中查询数据库及表的信息语句
/* -- 本文件主要是汇总了 Microsoft SQL Server 中有关数据库与表的相关信息查询语句. -- 下面的查询语句中一般给出两种查询方法, -- A方法访问系统表,适应于SQL 20 ...
- mysql常用的一些命令,用于查看数据库、表、字段编码
1.查看数据库支持的所有字符集 show character set;或show char set; 2.查看当前状态 里面包括当然的字符集设置 status或者\s ...
随机推荐
- 【Python】directory字典类型
它的基本格式是(key是键,value是值): d = {key1 : value1, key2 : value2 } Example dir = {'Mic':1,'Sun':2} for k in ...
- 又续CSS3
这次主要讲呢 1.box-sizing属性 语法:box-sizing: content-box|border-box|inherit; box-sizing属性的用法 box-sizing属性可以为 ...
- Android笔记——Socket通信实现简单聊天室
两部分,客户端和服务端 ---------------------------------------------------------------- 客户端 1.为防止ANR异常,互联网连接可用 ...
- Infragist ics Ult imate 2015 Vol.1 - Product Keys
Ultimate ProductKeys 2015 Vol.1: 9122-1900164-4504144 9122-9300855-3994197 9122-7600717-4579130 9122 ...
- 【Leetcode】【Medium】Maximum Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest ...
- 【Z】段错误Segment Fault定位,即core dump文件与gdb定位
使用C++开发系统有时会出现段错误,即Segment Fault.此类错误程序直接崩溃,通常没有任何有用信息输出,很难定位bug,因而无从解决问题.今天我们介绍core dump文件,并使用gdb进行 ...
- good pics
- Sqlserver2008+搜索型注入技术
简单的判断搜索型注入漏洞存在不存在的办法是先搜索',如果出错,说明90%存在这个漏洞.然后搜索%,如果正常返回,说明95%有洞了. 然后再搜索一个关键字,比如2006吧,正常返回所有2006相关的信息 ...
- Intellii IDEA 中快速补全main方法:psvm
psvm可以快速补全main方法 效果:
- ADF中VO的删除操作初探
在ADF的VO中,真实提交更改是在commit 方法执行之后,如以下增加操作 EntityDefImpl departmentEODef = DepartmentEOImpl. getDefiniti ...