当前位置:网站首页>Mongodb basic exercises
Mongodb basic exercises
2022-07-05 20:17:00 【Why not sell egg cakes well】
10 practice 1
// Access to database
user my_test
// Insert a document
db.user.insert({
username:"subway"
});
// Query the document
db.user.find();
// To the database user Insert a document into the collection
db.user.insert({
username:"zhengji"
});
// Inquire about user Document for collection
db.user.find();
// Count the number of collection documents
db.user.find().count();
// Add... To the document address attribute , The value is huaguoshan
db.users.insert({username:"sunwukong",{$set:{address:"huaguoshan"}}});
// Document replacement
db.users.resplaceOne({username:"zhubajie"},{username="tangsen"});
// Delete document properties
db.user.update({username:"sunwukong"},{$unset:{address:1}});
// Add a... To the document hobby by {} Properties of
// The attribute value of a document can also be a document , At this time, this document is ” Embedded documents “
db.users.update({username:"sunwukong",{$set:{...}}})
//mongodb Support query directly through embedded document properties
// If you want to query documents through embedded documents , Attribute names must be quoted
db.users.find({'hobby.movie':"hero"});
// towards tangsen Add a new movie to Intersteller
//$push Used to add new elements to the array
//$addToSet Add a new element to the array , But don't repeat
db.users.update({username:"tangsen"},{$push:{"hobby.movies":"Installer"}});
// Delete likes beijing Users of
db.users.remove({"hobby.cities":"beijing"});
// Delete user aggregate
db.users.remove({});
db.users.drop();
// towards numbers Insert 2000 Data
for(var i=1;i<=20000;i++){
db.numbers.insert({num:i});
}
// Performance optimization
var arr=[];
for(var i=1;i<=20000;i++){
arr.push({num:i});
}
db.numbers.insert(arr);
11 practice 2
Inquire about
// Inquire about numbers in num by 500 Documents
db.numbers.find({num:500})
// Inquire about numbers in num>500 Documents
db.numbers.find({num:{$gt:500}});
// Inquire about num Less than 30 Documents
db.numbers.find({num:{$lt:30}});
// The query is greater than 40 Less than 50
db.numbers.find({num:{$gt:40,$lt:50}});
// check numbers Before the assembly 10 Data
db.numbers.find({num:{$lte:10}});
//limit Set the upper limit of display data benefits : You will never execute queries without conditions during development
db.numbers.find().limit(10);
// Check before 11-20 strip
//skip Used to skip a certain amount of data before
//skip(( Page number -1)* Number of entries per page )
db.numbers.find().skip(10).limit(10);
//mongo Automatic adjustment skip and limit Location The front and rear positions have no effect
13 practice 3
// Import collection into database
// Select the... To import collection
// Query salary less than 2000 The employees'
db.emp.find({sal:{$lt:2000}});
// Check salary at 1000-2000 staff
db.emp.find({sal:{$gt:1000,$lt:2000}});
// Check that the salary is less than 1000 Or greater than 2500 staff
// Wrong way db.emp.find({sal:{$lt:1000,$gt:2500}});
db.emp.find({$or:[{sal:{$lt:10000},${gt:2500}}]});
// Check all employees in the finance department
var depno=db.dept.findOne({dname:" Finance Department "}).deptno;
db.emp.find({depno:depno});
// Query all mgr by 7698 All employees
db.emp.find({mgr:7698});
// Wages below 1000 Employee salary plus 400
db.emp.updateMany({sal:{$lte:1000}},{$inc:{sal:400}});
边栏推荐
- 零道云新UI设计中
- Go language | 03 array, pointer, slice usage
- 【数字IC验证快速入门】7、验证岗位中必备的数字电路基础知识(含常见面试题)
- [quick start of Digital IC Verification] 1. Talk about Digital IC Verification, understand the contents of the column, and clarify the learning objectives
- 如何形成规范的接口文档
- 2022年7月4日-2022年7月10日(ue4视频教程mysql)
- Hong Kong stocks will welcome the "best ten yuan store". Can famous creative products break through through the IPO?
- 图嵌入Graph embedding学习笔记
- leetcode刷题:二叉树11(平衡二叉树)
- 信息学奥赛一本通 1339:【例3-4】求后序遍历 | 洛谷 P1827 [USACO3.4] 美国血统 American Heritage
猜你喜欢

Leetcode brush question: binary tree 14 (sum of left leaves)

Convolution free backbone network: Pyramid transformer to improve the accuracy of target detection / segmentation and other tasks (with source code)

Elk distributed log analysis system deployment (Huawei cloud)

Leetcode brush questions: binary tree 18 (largest binary tree)

Scala基础【HelloWorld代码解析,变量和标识符】

Go language | 01 wsl+vscode environment construction pit avoidance Guide

实操演示:产研团队如何高效构建需求工作流?
![[quick start to digital IC Verification] 8. Typical circuits in digital ICs and their corresponding Verilog description methods](/img/3a/7eaff0bf819c129b4f866388e57b87.png)
[quick start to digital IC Verification] 8. Typical circuits in digital ICs and their corresponding Verilog description methods

【数字IC验证快速入门】2、通过一个SoC项目实例,了解SoC的架构,初探数字系统设计流程

.Net分布式事务及落地解决方案
随机推荐
随机数生成的四种方法|Random|Math|ThreadLocalRandom|SecurityRandom
js方法传Long类型id值时会出现精确损失
淺淺的談一下ThreadLocalInsecureRandom
CTF逆向基础
About the priority of Bram IP reset
How to choose a good external disk platform, safe and formal?
【数字IC验证快速入门】6、Questasim 快速上手使用(以全加器设计与验证为例)
C langue OJ obtenir PE, ACM démarrer OJ
Leetcode brush question: binary tree 14 (sum of left leaves)
什么是pyc文件
Summer Challenge harmonyos - realize message notification function
C language OJ gets PE, OJ of ACM introduction~
Go language learning tutorial (XV)
JS implementation prohibits web page zooming (ctrl+ mouse, +, - zooming effective pro test)
Jvmrandom cannot set seeds | problem tracing | source code tracing
《乔布斯传》英文原著重点词汇笔记(十二)【 chapter ten & eleven】
.Net分布式事務及落地解决方案
计算lnx的一种方式
炒股开户最低佣金,低佣金开户去哪里手机上开户安全吗
c语言oj得pe,ACM入门之OJ~