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 ...
随机推荐
- C# 转换运算符:implicit(隐式),explicit(显示)
//A类 class Cls1 { public string name; //构造函数 public Cls1(string name) { this.name = name; } //implic ...
- 《C++ Primer Plus》读书笔记之——处理数据
本文旨在记录在阅读<C++ Primer Plus>第五版的过程中,一些重点的知识点,方便以后查阅.本文将不断更新...... 一.第三章 处理数据 1.无符号整型不能存储负数值,其优点是 ...
- 二阶SQL注入理解与体会
一:SQL注入分类 SQL注入一般分为两类:一阶SQL注入(普通SQL注入),二阶SQL注入 二:二者进行比较 0x01:一阶SQL注入: 1:一阶SQL注入发生在一个HTTP请求和响应中,对系统的攻 ...
- Nginx配置虚拟机,url重写,防盗链
配置目录: · 虚拟主机 · PHP支持 · URL重写 · 防止盗链 · 持续更新… 一.虚拟主机 1.创建 文件格式:{域名}.conf 具体如下: $ s ...
- Timer类注意事项
Java的一个Timer对象可以执行多个Timertask任务,但是一个Timer对象本身只有一个线程,如果向他提交多个task,并且某个task相当耗时的话,其他的task即使到了执行时间,仍然会等 ...
- UVA12034 Race
嘟嘟嘟 令dp[i]表示在n个人中,有 i 个人获得第一名的方案数,转移方程为dp[i] = C(i, n) * dp[n - i].C(i, n)就是从n个人中选 i 个第一,那么剩下的n - i ...
- window.jQuery || document.write("<script src='__PUBLIC__/assets/js/jquery.js'>"+"<"+"/script>")
今天无意中看到这样一段代码 <script type="text/javascript"> window.jQuery || document.write(" ...
- springmvc和easyui使用ajax前台后台互传数据,假删除提示警告问题。
前台 //删除 多/单条数据 function del(cid){ var id=''; if(cid=='-1'){ if(getSelections().length > 0){ id=ge ...
- CPP-基础:信号量
windows api 多线程---信号量 信号量(Semaphore)和互斥量一样,属于内核对象.它自动执行可用资源查询的测试,如果有可用资源,则可用资源的计数减少1,从而避免其它线程请求资源.当该 ...
- javascript中filter方法
array1.filter(callbackfn[, thisArg]) 參數 參數 定義 array1 必要項. 陣列物件. callbackfn 必要項. 最多接受三個引數的函式. filte ...