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 ...
随机推荐
- centos7 配置虚拟交换机(物理交换机truck端口设置)(使用brctl)
转自:http://blog.csdn.net/qq_21398167/article/details/46409503 虚拟交换机配置 inux VLAN配置(vconfig) 安装vlan(vco ...
- Codeforces_801
A.直接暴力就行了,先把能组合的按线性组合掉,再枚举剩下相邻没用过的. #include<bits/stdc++.h> using namespace std; string s; ] = ...
- CCF_201403-1_相反数
按绝对值排序,因为没相同的数,直接遍历比较一遍即可. #include<iostream> #include<cstdio> #include<algorithm> ...
- How to check sqlsever table data type identity status ?
Unlike in Oracle, sqlserver has an special data type in order by make identity growth. But what abou ...
- 微信小程序面试题总结
A类问题 1 请谈谈微信小程序主要目录和文件的作用? project.config.json 项目配置文件,用得最多的就是配置是否开启https校验: App.js 设置一些全局的基础数据等: App ...
- Scala函数式编程(五) 函数式的错误处理
前情提要 Scala函数式编程指南(一) 函数式思想介绍 scala函数式编程(二) scala基础语法介绍 Scala函数式编程(三) scala集合和函数 Scala函数式编程(四)函数式的数据结 ...
- [redis读书笔记] 第二部分 sentinel
1.sentinel的初始化,会制定master的IP和port,然后sentinel会创建向被监视主服务器的命令连接和订阅连接: - 命令连接是用来和主服务器之间进行命令通信的 - 订阅连接,用于 ...
- 1 Nginx + 12 Tomcat +2DB 实现2个程序负载均衡
根据真实生产环境 总结. 硬件:共计5台服务器 1台负载windows.2台业务windows.2台数据库linux 业务:运行两个程序,两个数据库 具体:63服务器安装 Nginx 做负载 :61 ...
- Day17-18前端学习之路——常用语句资料库
一.var 与 let 的区别 var: 可以先初始化再声明该变量; 可以根据需要多次声明相同名称的变量 var myName = 'Chris'; var myName = 'Bob'; let m ...
- HDP之HBase性能调优
(官方文档翻译及整理) 一.系统级调优 1.保证充足的RAM 2.64位的操作系统 3.Linux的swappiness设置为0 : sysctl vm.swappiness=10 vim /etc/ ...