当前位置:网站首页>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}});
边栏推荐
- 怎么挑选好的外盘平台,安全正规的?
- . Net distributed transaction and landing solution
- Parler de threadlocal insecurerandom
- [quick start of Digital IC Verification] 1. Talk about Digital IC Verification, understand the contents of the column, and clarify the learning objectives
- Let's talk about threadlocalinsecurerandom
- Leetcode skimming: binary tree 10 (number of nodes of a complete binary tree)
- Leetcode brush question: binary tree 13 (the same tree)
- Station B up builds the world's first pure red stone neural network, pornographic detection based on deep learning action recognition, Chen Tianqi's course progress of machine science compilation MLC,
- Codeforces Round #804 (Div. 2) - A, B, C
- Scala基础【HelloWorld代码解析,变量和标识符】
猜你喜欢
Station B up builds the world's first pure red stone neural network, pornographic detection based on deep learning action recognition, Chen Tianqi's course progress of machine science compilation MLC,
[quick start of Digital IC Verification] 9. Finite state machine (FSM) necessary for Verilog RTL design
【愚公系列】2022年7月 Go教学课程 004-Go代码注释
Database logic processing function
js实现禁止网页缩放(Ctrl+鼠标、+、-缩放有效亲测)
【数字IC验证快速入门】7、验证岗位中必备的数字电路基础知识(含常见面试题)
Rainbond 5.7.1 支持对接多家公有云和集群异常报警
港股将迎“最牛十元店“,名创优品能借IPO突围?
无卷积骨干网络:金字塔Transformer,提升目标检测/分割等任务精度(附源代码)...
Leetcode(695)——岛屿的最大面积
随机推荐
MySql的root密码忘记该怎么找回
c語言oj得pe,ACM入門之OJ~
Leetcode brush question: binary tree 13 (the same tree)
Leetcode brush questions: binary tree 11 (balanced binary tree)
Debezium series: idea integrates lexical and grammatical analysis ANTLR, and check the DDL, DML and other statements supported by debezium
Leetcode skimming: binary tree 10 (number of nodes of a complete binary tree)
处理文件和目录名
走入并行的世界
基金网上开户安全吗?去哪里开,可以拿到低佣金?
Oracle tablespace management
Ffplay document [easy to understand]
- Oui. Net Distributed Transaction and Landing Solution
leetcode刷题:二叉树14(左叶子之和)
Go language learning tutorial (16)
信息学奥赛一本通 1339:【例3-4】求后序遍历 | 洛谷 P1827 [USACO3.4] 美国血统 American Heritage
关于BRAM IP复位的优先级
【愚公系列】2022年7月 Go教学课程 004-Go代码注释
leetcode刷题:二叉树15(找树左下角的值)
ByteDance dev better technology salon was successfully held, and we joined hands with Huatai to share our experience in improving the efficiency of web research and development
解决php无法将string转换为json的办法