当前位置:网站首页>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}});
边栏推荐
- Zero cloud new UI design
- A way to calculate LNX
- [quick start of Digital IC Verification] 6. Quick start of questasim (taking the design and verification of full adder as an example)
- 1: Citation;
- leetcode刷题:二叉树13(相同的树)
- Based on vs2017 and cmake GUI configuration, zxing and opencv are used in win10 x64 environment, and simple detection of data matrix code is realized
- [quick start of Digital IC Verification] 1. Talk about Digital IC Verification, understand the contents of the column, and clarify the learning objectives
- MySql的root密码忘记该怎么找回
- Is it safe for Guosen Securities to open an account online?
- Go language | 01 wsl+vscode environment construction pit avoidance Guide
猜你喜欢

Securerandom things | true and false random numbers

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

Leetcode skimming: binary tree 16 (path sum)

Mysql频繁操作出现锁表问题

Zero cloud new UI design

Database logic processing function

Hong Kong stocks will welcome the "best ten yuan store". Can famous creative products break through through the IPO?
![[quick start of Digital IC Verification] 6. Quick start of questasim (taking the design and verification of full adder as an example)](/img/6d/110b87747f0a4be52da9fd49a05b82.png)
[quick start of Digital IC Verification] 6. Quick start of questasim (taking the design and verification of full adder as an example)

JS implementation prohibits web page zooming (ctrl+ mouse, +, - zooming effective pro test)

Leetcode brush questions: binary tree 11 (balanced binary 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
Oracle-表空间管理
Debezium series: modify the source code to support UNIX_ timestamp() as DEFAULT value
How to retrieve the root password of MySQL if you forget it
银河证券在网上开户安全吗?
Minimum commission for stock trading account opening, where to open an account with low commission? Is it safe to open an account on your mobile phone
基金网上开户安全吗?去哪里开,可以拿到低佣金?
BZOJ 3747 POI2015 Kinoman 段树
微信小程序正则表达式提取链接
leetcode刷题:二叉树13(相同的树)
Let's talk about threadlocalinsecurerandom
本季度干货导航 | 2022年Q2
IC科普文:ECO的那些事儿
Go language learning tutorial (XV)
Leetcode skimming: binary tree 16 (path sum)
Elk distributed log analysis system deployment (Huawei cloud)
Convolution free backbone network: Pyramid transformer to improve the accuracy of target detection / segmentation and other tasks (with source code)
处理文件和目录名