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 ...
随机推荐
- hive安装启动错误总结
错误一: Exception in thread "main" java.lang.NoClassDefFoundError: jline/console/completer/Ar ...
- 如何最快实现物流即使查询功能-物流轨迹查询API
上一篇文章我们介绍了一个物流服务提供商,推荐大家使用快递鸟接口,主要介绍了如何注册账号,获得密钥,找不到注册地址的,我在发一下: http://kdniao.com/reg 今天我们来聊如何利用快递鸟 ...
- Codeforces_797
学了一学期还是那么菜. 好久没更新,还是得放点东西的. A.贪心最小的素因子,k = 1时,直接输出n就可以了. #include<bits/stdc++.h> using namespa ...
- 2020你还不会Java8新特性?
Java8(1)新特性介绍及Lambda表达式 前言: 跟大娃一块看,把原来的电脑拿出来放中间看视频用 --- 以后会有的课程 难度 深入Java 8 难度1 并发与netty 难度3 JVM 难度4 ...
- 一口气说出 9种 分布式ID生成方式,面试官有点懵了
整理了一些Java方面的架构.面试资料(微服务.集群.分布式.中间件等),有需要的小伙伴可以关注公众号[程序员内点事],无套路自行领取 本文作者:程序员内点事 原文链接:https://mp.weix ...
- 9.3.1 map端连接- DistributedCache分布式缓存小数据集
1.1.1 map端连接- DistributedCache分布式缓存小数据集 当一个数据集非常小时,可以将小数据集发送到每个节点,节点缓存到内存中,这个数据集称为边数据.用map函数 ...
- 我的一个配置redux(实现一次存储与调用方法)之旅
前言 : 今天呢,就配置一下redux,redux的重要性呢,就叭叭叭一大堆,什么也没有带着配置一次来的重要,因为许多涉及到的属性和方法,用法是活的,但格式是需要记忆的. 过程中不要嫌我唠叨,有的地方 ...
- java虚拟机jvm启动后java代码层面发生了什么?
java虚拟机jvm启动后java代码层面发生了什么? 0000 我想验证的事情 java代码在被编译后可以被jdk提供的java命令进行加载和运行, 在我们的程序被运行起来的时候,都发生了什么事情, ...
- php基础编程-php连接mysql数据库-mysqli的简单使用
很多php小白在学习完php基础后,或多或少要接触到数据库的使用.而mysql数据库是你最好的选择,本文就mysql来为大家介绍php如何连接到数据库. PHP MySQLi = PHP MySQL ...
- 数据算法 --hadoop/spark数据处理技巧 --(17.小文件问题 18.MapReuce的大容量缓存)
十七.小文件问题 十八.MR的大容量缓存 在MR中使用和读取大容量缓存,(也就是说,可能包括数十亿键值对,而无法放在一个商用服务器的内存中).本次提出的算法通用,可以在任何MR范式中使用.(eg:MR ...