MongoDB Shell 命令
更新列名
db.Stores.update({}, {$rename : {"StoreId" : "MetaId"}}, false, true)
查询长度
db.getCollection("Stores_Navigations").find({$where:'this.StoreId.length>2'},{Name:0})
查询总条数
db.getCollection("Stores_BusinessLogs").find({}).count()
区间查询
db.getCollection("Cards").find({'StoreId':1139,'CardNo':{'$gte':'90225001','$lte':'90295000'}})
排序 1升序 -1降序
db.getCollection("Stores_BusinessLogs").find().sort({"CreationTime":1})
更改字段类型
// 16代表int
db.Stores_Experts.find({'PicId' : { $type : 16 }}).forEach(function(x) {x.PicId = String(x.PicId);db.Stores_Experts.save(x); })
字段类型表
| 类型 | 对应数字 | 别名 |
|---|---|---|
| Double | 1 | double |
| String | 2 | string |
| Object | 3 | object |
| Array | 4 | array |
| Binary data | 5 | binData |
| Undefined | 6 | undefined |
| ObjectId | 7 | objectId |
| Boolean | 8 | “bool” |
| Date | 9 | “date” |
| Null | 10 | “null” |
| Regular Expression | 11 | “regex” |
| DBPointer | 12 | “dbPointer” |
| JavaScript | 13 | “javascript” |
| Symbol | 14 | “symbol” |
| JavaScript(with scope) | 15 | “javascriptWithScope” |
| 32-bit integer | 16 | “int” |
| Timestamp | 17 | “timestamp” |
| 64-bit integer | 18 | “long” |
| Min key | -1 | “minKey” |
| Max key | 127 | “maxKey” |
| - | - | - |
添加一个字段. table 代表表名 , 添加字段 content,字符串类型
db.table.update({}, {$set: {content:""}}, {multi: true})
删除一个字段
db.table.update({},{$unset:{content:""}},false, true)
清空数据
db.table.remove({})
查询指定列
db.news.find( {}, { id: 1, title: 1 } )
修改列表
db.getCollection('Orders_Scores').update({},{$rename:{"OId":'MetaId'}},false,true)
添加索引
db.test.createIndex({"username":1})
db.Users_MobileAuthCodes.createIndex({"Code":1,"Mobile":1,"ExpiresTime":1},{"name":"MobileAuthCodes_Validate"})
group分组
db.getCollection("Users_GaoKaoScores").aggregate([{$match:{"IsDeleted":false}},{$group : {_id : "$UserId", count : {$sum : 1}}},{$sort:{"count":-1}}])
按条件修改update
db.getCollection('Stores_Navigations').update(
// query
{
"MenuKey" : 28
},
// update
{
$set:{"Url":"/tzy/choosebatch?type=3"}
},
false,
true
);
MongoDB Shell 命令的更多相关文章
- 孤荷凌寒自学python第五十六天通过compass客户端和mongodb shell 命令来连接远端MongoDb数据库
孤荷凌寒自学python第五十六天通过compass客户端和mongodb shell 命令来连接远端MongoDb数据库 (完整学习过程屏幕记录视频地址在文末) 今天是学习mongoDB数据库的第二 ...
- MongoDB 基础命令 (MongoDB Shell)
1.我们 mongodb 安装成功后,用上一篇的方法启动 mongodb服务 然后使用 mongodb shell 来做数据库的增删改查 2.创建数据库 语法: use 数据库名称 案例: > ...
- 快速掌握mongoDB(一)——mongoDB安装部署和常用shell命令
1.mongoDB简介 mongoDB 是由C++语言编写的,是一种分布式的面向文档存储的开源nosql数据库.nosql是Not Only SQL的缩写,是对不同于传统的关系型数据库的数据库管理系统 ...
- MongoDB通过JavaDriver执行shell命令,例如创建sharding collection
Mongodb的java driver本身的接口 void createCollection(String collectionName, CreateCollectionOptions create ...
- mongoDB(一)——mongoDB安装部署和常用shell命令
1.mongoDB简介 mongoDB 是由C++语言编写的,是一种分布式的面向文档存储的开源nosql数据库.nosql是Not Only SQL的缩写,是对不同于传统的关系型数据库的数据库管理系统 ...
- MongoDB经典入门(2)--shell命令
MongoDB是MongoDB自带的交互式Javascript shell,用来对MongoDB进行操作和管理的交互式环境. 使用 "./mongo --help" 可查看相关连接 ...
- MongoDB基础命令笔记
一.创建数据库 use foobar 二.创建集合 db.persons.insert({name:"zhaomin",age:23}) 三.查找 db.persons.find( ...
- MongoDB常用命令
本文整理了一年多以来我常用的MongoDB操作,涉及mongo-shell.pymongo,既有运维层面也有应用层面,内容有浅有深,这也就是我从零到熟练的历程. MongoDB的使用之前也分享过一篇, ...
- MongoDB 基础命令行
本文专门介绍MongoDB的命令行操作.其实,这些操作在MongoDB官网提供的Quick Reference上都有,但是英文的,为了方便,这里将其稍微整理下,方便查阅. 登录和退出 mongo命令直 ...
随机推荐
- mosquitto 常用命令
原文:https://www.cnblogs.com/smartlife/articles/10182136.html 常用命令 订阅主题 mosquitto_sub -h 192.168.0.1 - ...
- kafka在zookeeper创建使用了哪些znode节点?
我们都知道kafka利用zookeeper做分布式管理,具体创建使用了哪些znode节点呢? 答案均在源码的ZkData.scala文件中,具体路径如下: https://github.com/apa ...
- instr函数的用法
1.定义 instr函数返回要截取的字符串在源字符串中的位置 语法如下: instr( string1, string2 [, start_position [, nth_appearance ] ...
- Libs - 软件下载网站
下载首页 > 网络工具 > FTP-工具 > 软件列表 http://down.tech.sina.com.cn/list/29_4_9.html
- HubSpot company数据在UI上的展示和通过API方式进行获取
在网页查看所有的company: https://app.hubspot.com/contacts/6798828/companies/list/view/all/? 打开第一个名为SAP的compa ...
- flink SourceFunction SinkFunction timeWindowAll reduce
1.实现SourceFunction接口生成数据源 /** * @Description: 产生数据 traceid,userid,timestamp,status,response time */ ...
- PHP查询附近的人及其距离的实现方法
1.附近的人 //获取该点周围的4个点 $distance = 1;//范围(单位千米) $lat = 113.873643; $lng = 22.573969; define('EARTH_RADI ...
- MySQL Error--InnoDB Table mysqlinnodb_index_stats has length mismatch in the column
使用MySQL 5.7.24版本的安装文件替换MySQL 5.7.19版本的安装文件,数据库复制频繁中断,查看error日志发现下面错误: [Warning] InnoDB: Table mysql/ ...
- 06. redis cluster
目录 Redis Cluster redis cluster 特点 搭建redis cluster 访问redis cluster redis-cli 访问redis cluster 重新分片数据 新 ...
- Linux文件增删改
Linux目录/文件增删改 创建文件 (1) # touch <文件名称> (2) 花括号展开 touch /root/{1,3,9}.txt touch /root/{0..100}. ...