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 ...
随机推荐
- javaIO笔记
原创 File类 实例化 new File(path); File.separator 分隔符 创建文件的常规做法
- ATL的GUI程序设计(3)
第三章 ATL的窗口类 CWindowImpl.CWindow.CWinTraits,ATL窗口类的奥秘尽在此三者之中.在本章里,李马将为你详细解说它们的使用方法.另外,本章的内容也可以算是本书的核心 ...
- QQ IP 地址查询相关
1.QQwry.dat格式分析和查询IP位置的PHP程序 以前的追捕数据库太大,而且很久没有更新了. 所以我想到利用QQwry.dat这个文件查询IP所在位置,QQwry.dat 在很多地方都能找到, ...
- thinkphp3关闭Runtime中的日志方法
将LOG_LEVEL允许记录的日志级别设置为空,则不会记录日志
- WeChall_PHP 0817 (PHP, Exploit)
I have written another include system for my dynamic webpages, but it seems to be vulnerable to LFI. ...
- BZOJ 2733 [HNOI2012]永无乡 (权值线段树启发式合并+并查集)
题意: n<=1e5的图里,在线连边.查询某连通块第k大 思路: 练习线段树合并的好题,因为依然记得上一次启发式合并trie的时候内存爆炸的恐怖,所以这次还是用了动态开点.回收 听说启发式合并s ...
- Codevs 1205 单词反转(Vector以及如何输出string)
题意:倒序输出句子中的单词 代码: #include<cstdio> #include<iostream> #include<string> #include< ...
- gulp 压缩文件2 摘
一下代码用来简单的压缩 .js 和 .css ; 在cmd里执行 gulp minifycss minifyjs,各task执行是正常的. 注意,先安装后相应的模块,建议安装到本地. 说 ...
- Standby Redo Logs的前世今生与最佳实践
编辑手记:使用过Data Guard的人应该对于Standby Redo Logs都不陌生,在配置了 Standby Redo Logs的standby中,能够进行日志的实时应用,同时Standby ...
- 如何在kalilinux上安装docker
如何在kalilinux上安装docker 0X00安装背景 在windows上安装docker使用未果后,便决定在kalilinux上安装一个docker 0X01安装步骤 分别在linux终端执行 ...