mongodb修改数据语句_MongoDB安装及简单的'增删改查'语句
* 1. 简介
* 推荐理由
* MongoDB 是一个基于分布式的开源文件存储的数据库。由 C++ 语言编写。旨在为 WEB 应用提供可扩展的高性能数据存储解决方案。
* MongoDB是一个介于关系数据库和非关系数据库之间的产品, 是非关系数据库当中功能最丰富,最像关系数据库的。他支持的数据结构非常松散,是类似json的bjson格式,因此可以存储比较复杂的数据类型。 Mongo最大的特点是他支持的查询语言非常强大,其语法有点类似于面向对象的查询语言,几乎可以实现类似关系数据库单表查询的绝大部分功能,而且还支持对数据建立索引。
* 分布式优缺点
* 优点
* 可靠性(容错) :
* 分布式计算系统中的一个重要的优点是可靠性。一台服务器的系统崩溃并不影响到其余的服务器。
* 可扩展性:
* 在分布式计算系统可以根据需要增加更多的机器。
* 资源共享:
* 共享数据是必不可少的应用,如银行,预订系统。
* 灵活性:
* 由于该系统是非常灵活的,它很容易安装,实施和调试新的服务。
* 更快的速度:
* 分布式计算系统可以有多台计算机的计算能力,使得它比其他系统有更快的处理速度。
* 开放系统:
* 由于它是开放的系统,本地或者远程都可以访问到该服务。
* 更高的性能:
* 相较于集中式计算机网络集群可以提供更高的性能(及更好的性价比)。
* 不管我们学习什么数据库都应该学习其中的基础概念,在mongodb中基本的概念是 数据库/集合/文档
![image](http://upload-images.jianshu.io/upload_images/10517060-0523815f460967f1.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* 例子
* SQL
* id user_name email age
* 1 A ab@163.com 25
* 2 b bb@163.com 32
* MongoDB
* {
* "_id":ObjectId("1234567890123456789012f3"),
* "user_name":"A",
* "email":"ab@163.com"
* "age":25
* }
* {
* "_id":ObjectId("1234567890123456789012f2"),
* "user_name":"b",
* "email":"bb@163.com"
* "age":32
* }
* 2. Docker方式安装MongoDB 3.7.9版本(这个步骤,不必练习!!)
![image](http://upload-images.jianshu.io/upload_images/10517060-061a658d15bb5f2a.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* [https://hub.docker.com/_/mongo/](https://hub.docker.com/_/mongo/)# MongoDB Docker官网
* 按照提示,下拉想要的版本镜像
* Container shell access and viewing MongoDB logs
* $ docker exec -it some-mongo bash # 进入容器
* $ docker logs some-mongo # 查看容器启动日志
* 推荐启动Docker镜像方式
* (1) docker run -d --name some-mongo -v /home/jet/mongo_data_db:/data/db -p 27017:27017 -e MONGO_INITDB_ROOT_USERNAME=mongoadmin -e MONGO_INITDB_ROOT_PASSWORD=secret mongo:3.7.9
* (2) docker run -it --rm --link some-mongo:mongo mongo mongo --host mongo -u mongoadmin -p secret --authenticationDatabase admin some-db
![image](http://upload-images.jianshu.io/upload_images/10517060-e3f114f4caf0e861.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* # 这是整了2个容器
![image](http://upload-images.jianshu.io/upload_images/10517060-9b88f7db96cdfe52.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* 或者用1个容器,直接1个容器里启动
![image](http://upload-images.jianshu.io/upload_images/10517060-17b9f0d872948c59.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image](http://upload-images.jianshu.io/upload_images/10517060-599242aaab8b30cd.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* 3\. Docker方式安装 MongoDB 3.2版本 ( 推荐安装这个版本)
* 运行如下命令,启动 MongoDB
* docker run --name some-mongo -v /home/jet/mongo_data_db/:/data/db -p 27017:27017 -d mongo:3.2
![image](http://upload-images.jianshu.io/upload_images/10517060-cc9930c3eae85782.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* 创建个用户 root2 / 123456 # 以后就需要用认证才能连接
* db.createUser({user:'root2',pwd:'123456',roles:[{role:'root',db:'admin'}]})
* # role:'root'为最高权限,可以在admin数据库中任何操作
* 4. 可视化工具连接MongoDB
* MongoBooster # 下载地址: [https://nosqlbooster.com/downloads](https://nosqlbooster.com/downloads)
![image](http://upload-images.jianshu.io/upload_images/10517060-d0e11ee92272509e.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* MongoBooster 连接 MongoDB3.2版本没问题,其他高版本不支持。
* 使用工具 NoSQLBooster 连接 MongoDB
* 3.1 无认证方式的连接
![image](http://upload-images.jianshu.io/upload_images/10517060-6c3115102fcaa138.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image](http://upload-images.jianshu.io/upload_images/10517060-f95c2fe6ff9133d9.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* 3.2 有认证的连接
![image](http://upload-images.jianshu.io/upload_images/10517060-d80f789a4cae41d7.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* 5\. MongoDB 查询介绍
* 认证、查询所有用户
![image](http://upload-images.jianshu.io/upload_images/10517060-49533a1cd2678043.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* show dbs:显示数据库列表
![image](http://upload-images.jianshu.io/upload_images/10517060-41ea3364a0527355.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* show collections:显示当前数据库中的集合(类似关系数据库中的表)
![image](http://upload-images.jianshu.io/upload_images/10517060-aaf2ee90ce98b32c.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image](http://upload-images.jianshu.io/upload_images/10517060-47c526b6fa56596a.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image](http://upload-images.jianshu.io/upload_images/10517060-faccd4be045ef995.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* # use admin:切换当前数据库至admin数据库,这和MySQL里面的意思一样
![image](http://upload-images.jianshu.io/upload_images/10517060-261ddf3de63c9fe9.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* show users:显示用户
![image](http://upload-images.jianshu.io/upload_images/10517060-1ca90b8560974836.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* db.help() # 显示数据库操作命令
![image](http://upload-images.jianshu.io/upload_images/10517060-1d9380f667937cc3.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* Help查看命令提示
![image](http://upload-images.jianshu.io/upload_images/10517060-3a72b18be075809d.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* help
* db.help();
* db.yourColl.help();
* db.youColl.find().help();
* rs.help();
* db.foo.help() # 显示集合操作命令,同样有很多的命令,foo指的是当前数据库下,一个叫foo的集合
![image](http://upload-images.jianshu.io/upload_images/10517060-c1f8770c64e942ea.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* db.system.users.find():对于当前数据库中的 system.users 集合进行数据查找(由于没有条件,会列出所有数据)
![image](http://upload-images.jianshu.io/upload_images/10517060-d49b996ae90d2fa6.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* # select * from system.users;
* db.system.users.find( { user : 'root1' } ) # 对于当前数据库中的 system.users 集合进行查找,条件是数据中有一个属性叫user,且 user 的值为 'root1'
![image](http://upload-images.jianshu.io/upload_images/10517060-83fe31db9678d559.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* 等同于Mysql中: select * from system.users where user = 'root1' ;
* db.col2.find({title:'NoSQL Overview'},) 与 db.col2.find({title:'NoSQL Overview'}) 查询结果都一样
![image](http://upload-images.jianshu.io/upload_images/10517060-72ea36a98a4317d6.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image](http://upload-images.jianshu.io/upload_images/10517060-46bc2883d3e43f1b.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image](http://upload-images.jianshu.io/upload_images/10517060-c9221daebb089e42.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* 插入数据
![image](http://upload-images.jianshu.io/upload_images/10517060-338f2dab0a45b2fa.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image](http://upload-images.jianshu.io/upload_images/10517060-549348c4814cb334.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image](http://upload-images.jianshu.io/upload_images/10517060-e8a5d12032d068d1.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* // 插入数据时,name / 'name' / "name" 都是一样的
* insert VS save
![image](http://upload-images.jianshu.io/upload_images/10517060-0e7e18e5ec6832f7.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image](http://upload-images.jianshu.io/upload_images/10517060-755be8d24991e4e0.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image](http://upload-images.jianshu.io/upload_images/10517060-d386dd82c15eca3b.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image](http://upload-images.jianshu.io/upload_images/10517060-d96f704ddf81622e.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* 集合中文档中的域可以多样化
![image](http://upload-images.jianshu.io/upload_images/10517060-0f899998ce95be2d.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* 查询去掉后的当前聚集集合中的某列的重复数据
![image](http://upload-images.jianshu.io/upload_images/10517060-59b07a6e6c094545.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image](http://upload-images.jianshu.io/upload_images/10517060-c63939c36216cc06.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image](http://upload-images.jianshu.io/upload_images/10517060-0b2957675969a0ca.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image](http://upload-images.jianshu.io/upload_images/10517060-c1498edef61a27bc.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image](http://upload-images.jianshu.io/upload_images/10517060-da28f918fe7b02d6.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* db.test.distinct("name");
* 会过滤掉name中的相同数据
* 相当于:select distict name from userInfo;
* 查询多个条件同时成立,等同于 SQL中 and
![image](http://upload-images.jianshu.io/upload_images/10517060-4a1337010c0ca223.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image](http://upload-images.jianshu.io/upload_images/10517060-2b3bf96f99fb4c2f.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* // SQL中: select * from test where name = 'Lucky' and sex = 'Female' ;
* 查询age > 22的记录
![image](http://upload-images.jianshu.io/upload_images/10517060-a4764d80cb80e0cc.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image](http://upload-images.jianshu.io/upload_images/10517060-3e39d846f7f07eba.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* db.test.find({age: {$gt: 22}});
* 相当于:select * from userInfo where age >22;
![image](http://upload-images.jianshu.io/upload_images/10517060-2c900d2c5222cd86.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image](http://upload-images.jianshu.io/upload_images/10517060-f0d78f0d84b5db51.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image](http://upload-images.jianshu.io/upload_images/10517060-5e0837d54fecdc40.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* db.test.find({age:{$lt:20}})
* 相当于:select * from test where age <20;
* db.test.find({age: {$lte: 18}});
![image](http://upload-images.jianshu.io/upload_images/10517060-237eb117b01f9936.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* db.test.find({age: {$gte: 18}});
![image](http://upload-images.jianshu.io/upload_images/10517060-aa3241861bac1bfd.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* 相当于:select * from test where age >= 25;
* 20 >=age>=18
![image](http://upload-images.jianshu.io/upload_images/10517060-1eaab96176df6ea7.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image](http://upload-images.jianshu.io/upload_images/10517060-f8bd6e29e15b1cfb.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* db.test.find({age: {$gte: 18,$lte:20}});
* 等同于SQL: select * from test where age between 18 and 20 ;
* 不等于 $ne
![image](http://upload-images.jianshu.io/upload_images/10517060-39449797579e5e61.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image](http://upload-images.jianshu.io/upload_images/10517060-269f094a111a4eac.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* 在某范围内 $in
![image](http://upload-images.jianshu.io/upload_images/10517060-b328a54a37b04899.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image](http://upload-images.jianshu.io/upload_images/10517060-df894dce68407285.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* 不在某范围内 $nin
* $mod 取模 // 查询所有 age % 10 == 3 的docs
![image](http://upload-images.jianshu.io/upload_images/10517060-4a195aa49d355ae4.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* 模糊查询 查询 name 中包含 rek 的数据 // db.test.find({name:/rek/})
![image](http://upload-images.jianshu.io/upload_images/10517060-83c5ffb5bf8ed4e4.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* 查询name中以 Dere 开头的 // db.test.find({name:/^Der/})
![image](http://upload-images.jianshu.io/upload_images/10517060-381e0331801d13b4.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image](http://upload-images.jianshu.io/upload_images/10517060-77fbb046f174d772.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* 查询name中以 33 开头的 // db.test.find({name:/33$/})
![image](http://upload-images.jianshu.io/upload_images/10517060-c4cdce48f006ce15.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* 查询指定列name、age数据 // db.test.find({}, {name: 1, age: 1});
![image](http://upload-images.jianshu.io/upload_images/10517060-6be260470c76fb2e.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image](http://upload-images.jianshu.io/upload_images/10517060-5f88b9641b5b37da.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image](http://upload-images.jianshu.io/upload_images/10517060-9d18afa51184c879.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image](http://upload-images.jianshu.io/upload_images/10517060-60ba8602d7ba4b87.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image](http://upload-images.jianshu.io/upload_images/10517060-d4adb3d266e89ef0.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* 查询指定列name、age数据, age > 18 // db.test.find({age: {$gt: 18}}, {name: 1, age: 1});
![image](http://upload-images.jianshu.io/upload_images/10517060-b876a0a1d8d8ab05.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* 排序(按照年龄排序)
![image](http://upload-images.jianshu.io/upload_images/10517060-fe3e1e067c2bbe15.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image](http://upload-images.jianshu.io/upload_images/10517060-963054de9ed68356.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image](http://upload-images.jianshu.io/upload_images/10517060-176334ce3c7a3fc9.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* 升序:db.test.find().sort({age: 1});
* 降序:db.test.find().sort({age: -1});
* 或
![image](http://upload-images.jianshu.io/upload_images/10517060-8b64d0275d87f5eb.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image](http://upload-images.jianshu.io/upload_images/10517060-72e3ccf5a543cad3.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image](http://upload-images.jianshu.io/upload_images/10517060-19650206fd210974.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* 统计 count()
![image](http://upload-images.jianshu.io/upload_images/10517060-3254ea39c103b4f8.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* 查询前几条 // limit(n)
![image](http://upload-images.jianshu.io/upload_images/10517060-2abd3ef197f0360d.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image](http://upload-images.jianshu.io/upload_images/10517060-04b5a08872d99989.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image](http://upload-images.jianshu.io/upload_images/10517060-028f76e8e884c5d0.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image](http://upload-images.jianshu.io/upload_images/10517060-252989e00c23bb0e.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* 大量造数
![image](http://upload-images.jianshu.io/upload_images/10517060-0a03f64d17e64fb9.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* 删除
![image](http://upload-images.jianshu.io/upload_images/10517060-6b7b663b54232a4a.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image](http://upload-images.jianshu.io/upload_images/10517060-f5a2e764d595307f.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* 删除集合test2 // db.test2.drop()
* 删除当前数据库
![image](http://upload-images.jianshu.io/upload_images/10517060-92db5a2b073247dd.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image](http://upload-images.jianshu.io/upload_images/10517060-c092acdf95153489.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* 更新 // 不保留其它fields
![image](http://upload-images.jianshu.io/upload_images/10517060-d71d45a934f34770.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image](http://upload-images.jianshu.io/upload_images/10517060-3bc368890c1869c1.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* 更新 // 保留其它fields
![image](http://upload-images.jianshu.io/upload_images/10517060-f7bc6c188191528e.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image](http://upload-images.jianshu.io/upload_images/10517060-3b983664e0fbbadc.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* 更新 ? 新增
![image](http://upload-images.jianshu.io/upload_images/10517060-6a8e64b93776e3f1.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image](http://upload-images.jianshu.io/upload_images/10517060-dbfcac438367cbd0.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image](http://upload-images.jianshu.io/upload_images/10517060-dcb9653f0d2b9a90.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image](http://upload-images.jianshu.io/upload_images/10517060-1caa547629c5d91c.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* 清空集合
![image](http://upload-images.jianshu.io/upload_images/10517060-2c13bf616a30a8a0.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* 聚合
* 聚合(aggregate)主要用于处理数据(诸如统计平均值,求和等),并返回计算后的数据结果。
* 例子
* 一次性插入3条数据
* var d;
* d=[{
* title: 'MongoDB Overview',
* description: 'MongoDB is no sql database',
* by_user: 'runoob.com',
* url: 'http://www.runoob.com',
* tags: ['mongodb', 'database', 'NoSQL'],
* likes: 100
* },
* {
* title: 'NoSQL Overview',
* description: 'No sql database is very fast',
* by_user: 'runoob.com',
* url: 'http://www.runoob.com',
* tags: ['mongodb', 'database', 'NoSQL'],
* likes: 10
* },
* {
* title: 'Neo4j Overview',
* description: 'Neo4j is no sql database',
* by_user: 'Neo4j',
* url: 'http://www.neo4j.com',
* tags: ['neo4j', 'database', 'NoSQL'],
* likes: 750
* }];
* db.col2.insert(d);
![image](http://upload-images.jianshu.io/upload_images/10517060-a47f669a8861c479.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image](http://upload-images.jianshu.io/upload_images/10517060-f19bc53a2fe5a292.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* db.col2.aggregate().group({_id:"$by_user",count:{$sum:1}}) //根据by_user分组,统计个数
![image](http://upload-images.jianshu.io/upload_images/10517060-4fe0ec927b7b479c.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* > db.col2.aggregate().group({_id:"$by_user",count:{$sum:"$likes"}}) //以by_user分组,求和likes的值
![image](http://upload-images.jianshu.io/upload_images/10517060-a2e8fa138b33048f.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* > db.col2.aggregate().group({_id:null,count:{$sum:"$likes"}}) //不分组,只根据likes字段求和
![image](http://upload-images.jianshu.io/upload_images/10517060-405888a06456446f.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* 表达式 描述 实例
* $sum 计算总和。 db.mycol.aggregate([{$group : {_id : "$by_user", num_tutorial : {$sum : "$likes"}}}])
* $avg 计算平均值 db.mycol.aggregate([{$group : {_id : "$by_user", num_tutorial : {$avg : "$likes"}}}])
* $min 获取集合中所有文档对应值得最小值。 db.mycol.aggregate([{$group : {_id : "$by_user", num_tutorial : {$min : "$likes"}}}])
* $max 获取集合中所有文档对应值得最大值。 db.mycol.aggregate([{$group : {_id : "$by_user", num_tutorial : {$max : "$likes"}}}])
* MongoBooster 常用快捷方式
* 选中 - F6 / 或者点击到哪一行,按F6,执行的是最后一行的语句
* Ctrl +T //打开shell
* Ctrl + R //刷新
* Ctrl + D // 复制当前行到下一行
mongodb修改数据语句_MongoDB安装及简单的'增删改查'语句相关推荐
- mongodb修改数据语句_mongodb之一些简单的增删改查语句
数据库操作: show dbs;#查看数据库 use test;#如果没有就创建一个 db;#查看当前数据库 db.dropDatabase();#删除数据库 数据操作: show collectio ...
- mysql查询和修改一个命令_MYSQL的常用命令和增删改查语句
连接命令:mysql -h[主机地址] -u[用户名] -p[用户密码] 创建数据库:create database [库名] 显示所有数据库: show databases; 打开数据库:use [ ...
- 利用ajax获取数据对学生表进行简单的增删改查
前言 本次练习没有使用前端框架,默认以表格方式拼接渲染数据,后端数据返回没有采用规范的数据形式返回 默认你能用springboot-mybatis从后端获取到数据 spring boot 静态资源处理 ...
- SSM整合--简单的增删改查--修改用户信息
SSM整合--简单的增删改查 修改用户信息 修改用户信息 ## 根据id查找用户信息,显示在employ_update页面 ## 进行修改信息后,提交表单,保存数据### 1.根据id查询用户信息 h ...
- MySQL基础知识-MySQL概述安装,单表增删改查,函数,约束,多表查询,事物
MySQL基础知识-MySQL概述安装,单表增删改查,函数,约束,多表查询,事物 前言 1.MySQL概述 1.1数据库相关概念 1.2MySQL数据库 1.2.1版本 1.2.2下载 1.2.3安装 ...
- MyBatis学习--简单的增删改查
jdbc程序 在学习MyBatis的时候先简单了解下JDBC编程的方式,我们以一个简单的查询为例,使用JDBC编程,如下: 1 Public static void main(String[] arg ...
- Struts2 注解开发实现简单的增删改查,超详细教程
声明:此文是原创,如果需要转载请注明出处:https://blog.csdn.net/hunter_max/article/details/80575542 上一篇博客<Struts2 注解开发 ...
- java之简单的增删改查功能
目录 前言 一.查询 二.增加 三.删除 四.修改 五.界面展示: 前言 用增删改查写的简单版学生管理系统 运用了JavaScript,El表达式,c标签,mvc模式,三层架构,MySQL. 数据库辅 ...
- myBatis 简单的增删改查
myBatis 简单的增删改查 前面已经讲到用接口的方式编程.这种方式,要注意的一个地方就是.在User.xml 的配置文件中, mapper namespace="com.fjh.inte ...
最新文章
- 阿里云蒋江伟:我们致力于为世界提供70%的算力 | 凌云时刻
- 银行的双重生物识别实验,是双重麻烦还是双重安全?
- 用两个栈来实现一个队列,完成队列的Push和Pop操作。 队列中的元素为int类型。...
- BootStrap 组件和样式
- ftk学习记(combox篇)
- python json传参数可以传对象吗_廖雪峰的python系列教程(52)——IO编程之序列化...
- Java占Linux超过xms,linux下分析java程序占用CPU、内存过高
- storm中worker、executor、task之间的关系
- 如何避免程序员的中年危机?
- 锂离子电池性能测试软件,锂离子电池的常规性能测试方式介绍
- Linux线程编程之生产者消费者问题【转】
- js分页展示控件,传入简单参数就能使用的分页效果控件
- 【高频电子线路】[模型]LC并联谐振回路(第2章 谐振功率放大器)
- python调用nmap扫描全端口_python nmap 扫描服务器端口
- BMVC reading list
- 如何读懂 MySQL rw-lock 锁的统计信息
- 华南理工大学计算机科学与工程学院篡改,疑篡改研究生复试成绩!华工四人被停职接受调查...
- 智汇云校携手院校组织数千学生参加“2020华为中国大学生ICT大赛”
- 奇安信2022面试题
- java pdf库_Java中常用的操作PDF的类库
热门文章
- java敏感词关键词过滤
- 面试时衣服出汗了怎么办
- DiskGenius 百度云下载链接
- color a dir/s_2级绘本(A)Lesson 25:Kipper扮演小丑
- PCA(主成分分析-principal components analysis)学习笔记以及源代码实战讲解
- 这次经济危机的一些看法
- 解决Spring Spring Data JPA 错误: Page 1 of 1 containing UNKNOWN instances
- js生成二维码——QRCode.js中文文档
- Boosting(Adboost、GBDT、Xgboost)
- This beta version of Typora is expired,please download and install a newe最新解决方案