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 ...
随机推荐
- 娱乐往事,年初捡到1G PAR,平淡的日子泛起波澜
常听说这样的故事 垃圾佬捡到蓝牙键盘,于是配了一台上万的电脑 垃圾佬捡到机箱,于是配了一台带遥控的HTPC 垃圾佬捡到假NAS,于是组了20+T的RAID 而我,不是垃圾佬,更没有捡到过U盘,对突如其 ...
- Hibernate(四)
==================================投影(查询)=============================投影查询:查询一个持久化类的一个或多个属性值 1.将每条 ...
- (数据科学学习手札75)基于geopandas的空间数据分析——坐标参考系篇
本文对应代码已上传至我的Github仓库https://github.com/CNFeffery/DataScienceStudyNotes 1 简介 在上一篇文章中我们对geopandas中的数据结 ...
- C++静态成员函数小结
类中的静态成员真是个让人爱恨交加的特性.我决定好好总结一下静态类成员的知识点,以便自己在以后面试中,在此类问题上不在被动. 静态类成员包括静态数据成员和静态函数成员两部分. 一 静态数据成员: ...
- 什么是伪静态,以及ubuntu + apache 如何实现伪静态
原文链接:http://www.cnblogs.com/ainiaa/archive/2010/07/25/1784564.html php伪静态 一直在做php的开发工作.在开发的过程中老早就听说了 ...
- css: line-height 与box-sizing
css 1.line-hight: 行高line-height,是文本行基线这件的距离,不是字体大小,它确定了各个元素框的高度增加或减少多少. 对于块级元素:定义了元素中文本基线之间的最小距离. li ...
- NLP新秀 - Bert
目录 什么是Bert Bert能干什么? Bert和TensorFlow的关系 BERT的原理 Bert相关工具和服务 Bert的局限性和对应的解决方案 沉舟侧畔千帆过, 病树前头万木春. 今天介绍的 ...
- POJ_3627_贪心
题目描述: 给你N个数和一个总和,要求求出最少个数的数相加大于等于这个总和. 思路: 很简单的贪心,先排序,从大到小加一次,比较一次,直到符合条件. 我用了优先队列,运行时间好像多了一倍= = #in ...
- 【5min+】 巨大的争议?C# 8 中的接口
系列介绍 [五分钟的dotnet]是一个利用您的碎片化时间来学习和丰富.net知识的博文系列.它所包含了.net体系中可能会涉及到的方方面面,比如C#的小细节,AspnetCore,微服务中的.net ...
- 编辑crontab添加Linux计划任务
在做实验楼的比赛时的题目 用到了crontable 1. 为用户shiyanlou添加一个计划任务 2. 每天凌晨2点定时执行 3. 将/var/log/dpkg.log /var/log/mysql ...