使用mongo shell远程连接数据库
时间:2022-06-11
本文章向大家介绍使用mongo shell远程连接数据库,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
序
本文主要介绍一下如何使用mongo shell连接远程数据库
install
curl -o mongodb-linux-x86_64-3.2.4.tgz https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.2.4.tgz
tar -xvf mongodb-linux-x86_64-3.2.4.tgz
这个里头的bin就包含了mongo
shell
mongo mydb --username user1 --host 192.168.99.100 --port 27017 --password
—password后面不传参数,则会在命令行提示输入
查看空间占用
mydb:PRIMARY> db.stats()
{
"db" : "mydb",
"collections" : 7,
"objects" : 5762090,
"avgObjSize" : 437.28749533589377,
"dataSize" : 2519689904, //所有数据的总大小
"storageSize" : 1816985600, //所有数据占的磁盘大小
"numExtents" : 0,
"indexes" : 10,
"indexSize" : 84381696,
"ok" : 1
}
db.stats(1073741824);以G为单位 db.stats(1024)以kb为单位
查看集合
db.getCollectionNames()
查询
mydb:PRIMARY> db.mylog.find({"user_id":"12345"}).count()
help
mydb:PRIMARY> db.help()
DB methods:
db.adminCommand(nameOrDocument) - switches to 'admin' db, and runs command [ just calls db.runCommand(...) ]
db.auth(username, password)
db.cloneDatabase(fromhost)
db.commandHelp(name) returns the help for the command
db.copyDatabase(fromdb, todb, fromhost)
db.createCollection(name, { size : ..., capped : ..., max : ... } )
db.createUser(userDocument)
db.currentOp() displays currently executing operations in the db
db.dropDatabase()
db.eval() - deprecated
db.fsyncLock() flush data to disk and lock server for backups
db.fsyncUnlock() unlocks server following a db.fsyncLock()
db.getCollection(cname) same as db['cname'] or db.cname
db.getCollectionInfos([filter]) - returns a list that contains the names and options of the db's collections
db.getCollectionNames()
db.getLastError() - just returns the err msg string
db.getLastErrorObj() - return full status object
db.getLogComponents()
db.getMongo() get the server connection object
db.getMongo().setSlaveOk() allow queries on a replication slave server
db.getName()
db.getPrevError()
db.getProfilingLevel() - deprecated
db.getProfilingStatus() - returns if profiling is on and slow threshold
db.getReplicationInfo()
db.getSiblingDB(name) get the db at the same server as this one
db.getWriteConcern() - returns the write concern used for any operations on this db, inherited from server object if set
db.hostInfo() get details about the server's host
db.isMaster() check replica primary status
db.killOp(opid) kills the current operation in the db
db.listCommands() lists all the db commands
db.loadServerScripts() loads all the scripts in db.system.js
db.logout()
db.printCollectionStats()
db.printReplicationInfo()
db.printShardingStatus()
db.printSlaveReplicationInfo()
db.dropUser(username)
db.repairDatabase()
db.resetError()
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>) 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() current version of the server
doc
- mongo Shell Quick Reference
- IDHub亮相区块链行业巅峰盛宴 分享网络生活的“进化论”
- 总结:如何加速你的 WordPress 站点?
- 百年老牌的创新之路:看可口可乐如何用AI、大数据颠覆传统营销
- 微信小游戏上线,小程序或将成为未来的营销工具
- WooCommerce 自定义商品价格显示HTML结构
- 借助Github 为第三方WordPress 主题/插件添加“自动更新”功能
- vue-cli#2.0 webpack 配置分析
- 短代码插件S-shortcodes 更新2.4版本:修复font icon的冲突问题
- 景驰落户广州 王劲称不知百度为何指控 四条回应两大疑点
- 全球各行业2020年将需要270万位数据科学家
- 解决iOS 版Safari 中浮动(float)导致页面右侧偏移的bug
- 学而思网校又玩大了:引入人工智能技术,办了一场“人机对话”英语赛事
- 全球首个机器人公民索菲亚亮相2017双12知商节 引爆全场知识产权新高潮
- WP Settings Generator:生成WordPress设置相关代码的工具
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- Linux (Ubuntu 18.04) 下安装vim编辑器的方法
- 把windows下的字体安装到Linux系统下的方法介绍
- Ubuntu 7.10修改软件源的方法
- Linux 僵尸进程产生原因及解决方法
- Ubuntu17.04配置更换国内源的方法
- Centos7硬盘挂载方法
- linux sort多字段排序实例解析
- Linux中Centos7搭建Hadoop服务步骤
- Centos7实现磁盘限额设置方法
- 在CentOS中部署多节点Citus集群的详细步骤
- 建立自己的npm镜像服务器
- Hugo搭建博客(一)— 基本设置
- Canvas系列(1):直线图形
- 《进化:从孤胆极客到高效团队》读书笔记
- CentOS设置精准时间的方法