mongo shell
mongo shell
mongo 连接
本地
mongo # 连接127.0.0.1:27017
远程
mongo "mongodb://mongodb0.example.com:28015"
带认证的方式
mongo "mongodb://alice@mongodb0.examples.com:28015/?authSource=admin"
复制集
mongo "mongodb://mongodb0.example.com.local:27017,mongodb1.example.com.local:27017,mongodb2.example.com.local:27017/?replicaSet=replA"
mongo "mongodb+srv://server.example.com/" # DNS Seedlist Connection Format
SSL方式
mongo "mongodb://mongodb0.example.com.local:27017,mongodb1.example.com.local:27017,mongodb2.example.com.local:27017/?replicaSet=replA&ssl=true"
mongo shell 操作
db # 查看当前数据库
use <database> #使用数据库
当插入数据时会自动创建集合
在mongo第一次显示提示之前,会自动运行HOME目录下的.mongorc.js文件,如果不想加载,可以使用--norc参数
配置shell
cmdCount = 1;
prompt = function() {
return (cmdCount++) + "> ";
}
# 显示行数
Date
- Date() 返回string
- new Date() 返回ISODate
- ISODate() 返回ISODate
ObjectId
_id的类型
NumberLong
mongo shell中,默认认为数字为浮点型,为表示64位int型数据,可以用NumberLong
如果用$inc作用于NumberLone,将把此数转为浮点型
数字比较
| Query | Results |
|---|---|
| { “val”: 9.99 } | { “_id”: 2, “val”: 9.99, “description”: “Double” } |
| { “val”: NumberDecimal( “9.99” ) } | { “_id”: 1, “val”: NumberDecimal( “9.99” ), “description”: “Decimal” } |
| { val: 10 } | { “_id”: 3, “val”: 10, “description”: “Double” }{ “_id”: 4, “val”: NumberLong(10), “description”: “Long” }{ “_id”: 5, “val”: NumberDecimal( “10.0” ), “description”: “Decimal” } |
| { val: NumberDecimal( “10” ) } | { “_id”: 3,“val”:10, “description”: “Double” }{ “_id”: 4, “val”: NumberLong(10), “description”: “Long” }{ “_id”: 5, “val”: NumberDecimal( “10.0” ), “description”: “Decimal” } |
当double类型的数据进行比较时,会转换double的数据类型为decimal,而且会有误差
可以用type进行比对
db.inventory.find( { price: { $type: "decimal" } } )
shell操作指南
~/.dbshell:操作 记录
show dbs:查看 所有 数据库,不同的访问权限会有不同的结果
use <db>:使用数据库
show collections:查看所有集合
show users:查看当前所有用户
show roles:查看当前数据库所有角色,包括内建的
show profile:打印耗时1毫秒以上的操作5个
show databases:查看可访问的所有数据库
mongo shell的更多相关文章
- MongoDB error: couldn't connect to server 127.0.0.1:27017 src/mongo/shell/mongo.js(转)
rror: couldn't connect to server 127.0.0.1:27017 src/mongo/shell/mongo.js 一般这种情况就是:自己指定的数据库,所以不能.自动加 ...
- 常见的mongo shell命令
启动mongo shell 在windows下,双击mongo.exe可以启动mongo shell 查询库.表及选择库 查询所有库命令: show dbs 应用某一个db use jxs_datab ...
- MongoDB - The mongo Shell, mongo Shell Quick Reference
mongo Shell Command History You can retrieve previous commands issued in the mongo shell with the up ...
- MongoDB - The mongo Shell, Data Types in the mongo Shell
MongoDB BSON provides support for additional data types than JSON. Drivers provide native support fo ...
- MongoDB - The mongo Shell, Write Scripts for the mongo Shell
You can write scripts for the mongo shell in JavaScript that manipulate data in MongoDB or perform a ...
- MongoDB - The mongo Shell, Access the mongo Shell Help
In addition to the documentation in the MongoDB Manual, the mongo shell provides some additional inf ...
- MongoDB - The mongo Shell, Configure the mongo Shell
Customize the Prompt You may modify the content of the prompt by setting the variable prompt in the ...
- MongoDB - Introduction of the mongo Shell
Introduction The mongo shell is an interactive JavaScript interface to MongoDB. You can use the mong ...
- couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:145
当直接执行./mongo 出现这样的提示:couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:145 解决: ...
- mongo Shell初体验
mongo shell是一个MongoDB的交互式JavaScript接口.您可以使用mongo shell来查询和更新数据以及执行管理操作. 打开cmd命令行,输入mongo,就可以进入mongo ...
随机推荐
- python 不可变字典 inmutabledict的实现
python inmutabledict的实现 关于在python中如何实现不可变字典的方法.早在pep416中,就建议python官方实现inmutabledict,但是官方否认了.理由主要是 根据 ...
- Python黑客编程知识点整理
Python转义字符 转义字符 意义 ASCII码值(十进制) \a 响铃(BEL) 007 \b 退格(BS) ,将当前位置移到前一列 008 \f 换页(FF),将当前位置移到下页开头 012 \ ...
- kubernetes从私有仓库下载遇到的坑
1.必须要在所有的k8s节点上配置私有仓库的地址.(master和node) 2.创建secret kubectl create secret docker-registry secret名字 --d ...
- Java并发读书笔记:线程安全与互斥同步
目录 导致线程不安全的原因 什么是线程安全 不可变 绝对线程安全 相对线程安全 线程兼容 线程对立 互斥同步实现线程安全 synchronized内置锁 锁即对象 是否要释放锁 实现原理 啥是重进入? ...
- LUAMD5加密
md5里的方法: C:\Windows\System32>lua Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio > require( ...
- Linux 内存分析工具——free命令
在Linux系统经常被用作服务器系统.当服务器内存吃紧的时候,free命令是我们最常使用的内存分析工具. free使用介绍 free命令可以显示Linux系统中空闲的.已用的物理内存及swap内存,及 ...
- 后台+下载(wget)+多个下载url
有时候我们需要让linux下载多个文件,并且后台下载,不去占用当前控制台. 比如我们需要下载中文维基的三个文件: https://dumps.wikimedia.org/zhwiki/latest/z ...
- CentOS7.3下yum安装MariaDB10.3.12并指定utf8字符集
添加MariaDB的yum源,指定安装的版本,然后使用 yum 工具进行安装 参考MariaDB官方网站对应安装方法和步骤 https://downloads.mariadb.org/mariadb/ ...
- Python常用库 - os库
os简单介绍 os 模块提供了非常丰富的方法用来处理文件和目录 os关于目录路径的方法 # 获取当前路径 path = os.getcwd() # 获取当前绝对路径 os.path.abspath(p ...
- C#个推SDK推送安卓+iOS
下载个推SDK,找到这两个dll直接引用. using引用 using com.gexin.rp.sdk.dto; using com.igetui.api.openservice; using co ...