当前位置:网站首页>How does mongodb realize the creation and deletion of databases, the creation of deletion tables, and the addition, deletion, modification and query of data
How does mongodb realize the creation and deletion of databases, the creation of deletion tables, and the addition, deletion, modification and query of data
2022-07-07 09:29:00 【Yisu cloud】
MongoDB How to create and delete a database 、 Create delete table 、 Data addition, deletion, modification and query
This article mainly introduces “MongoDB How to create and delete a database 、 Create delete table 、 Data addition, deletion, modification and query ”, In daily operation , I believe a lot of people are MongoDB How to create and delete a database 、 Create delete table 、 There are doubts about data addition, deletion, modification and query , Xiao Bian consulted all kinds of materials , Sort out simple and easy-to-use operation methods , I hope to answer ”MongoDB How to create and delete a database 、 Create delete table 、 Data addition, deletion, modification and query ” Your doubts help ! Next , Please follow Xiaobian to learn !
One 、 Database usage
Turn on mongodb service : To manage the database , You have to turn on the service first , Turn on service usage
mongod --dbpath c:\mongodb
management mongodb database :( Must be in the new cmd Input in )
mongo
Clear the screen :
cls
Check all databases list
show dbs
Two 、 Create database
Using a database 、 Create database
use student
If you really want to create this database successfully , Then a data must be inserted .
You can't insert data directly into the database , You can only go to the assembly (collections) Insert data . There is no need to create a collection specifically , only
If you need to write some syntax to insert data, you will create a collection :
Insert a piece of data
db.student.insert({“name”:”xiaoming”});
db.student System discovery student It's a strange collection name , So the collection is automatically created .
Displays the current data set (mysql Chinese called Watch )
show collections
Delete database , Delete the current database
db.dropDatabase();
Delete the collection , Delete the specified collection Delete table
Delete the collection
db.COLLECTION_NAME.drop()db.user.drop()
3、 ... and 、 Insert ( increase ) data
insert data , With the insertion of data , The database was created successfully , The collection was also created successfully .
db. Table name .insert({"name":"zhangsan"}); student Collection name ( surface )
Four 、 Find data
1 、 Check all records
db.userInfo.find();
amount to :select* from userInfo;
2 、 Query the duplicate data of a column in the removed current aggregation set
db.userInfo.distinct("name");
It will filter out name The same data in
amount to :select distict name from userInfo;
3 、 Inquire about age = 22 The record of
db.userInfo.find({"age": 22});
amount to : select * from userInfo where age = 22;
4 、 Inquire about age > 22 The record of
db.userInfo.find({age: {$gt: 22}});
amount to :select * from userInfo where age >22;
5 、 Inquire about age < 22 The record of
db.userInfo.find({age: {$lt: 22}});
amount to :select * from userInfo where age <22;
6 、 Inquire about age >= 25 The record of
db.userInfo.find({age: {$gte: 25}});
amount to :select * from userInfo where age >= 25;
7 、 Inquire about age <= 25 The record of
db.userInfo.find({age: {$lte: 25}});
8 、 Inquire about age >= 23 also age <= 26 Pay attention to the writing style
db.userInfo.find({age: {$gte: 23, $lte: 26}});
9 、 Inquire about name Contained in the mongo The data of Fuzzy queries are used to search
db.userInfo.find({name: /mongo/});
amount to :%%
select * from userInfo where name like ‘%mongo%’;
10 、 Inquire about name China and Israel mongo At the beginning
db.userInfo.find({name: /^mongo/});
amount to :select * from userInfo where name like ‘mongo%’;
11 、 Query specified column name 、age data
db.userInfo.find({}, {name: 1, age: 1});
amount to :select name, age from userInfo;
Of course name It can also be used. true or false, When used ture In the case of the river name:1 The effect is the same , If you use false It's to exclude name, Show name Column information other than .
12 、 Query specified column name 、age data , age > 25
db.userInfo.find({age: {$gt: 25}}, {name: 1, age: 1});
amount to :select name, age from userInfo where age >25;
13 、 Sort by age 1 Ascending -1 Descending
Ascending :db.userInfo.find().sort({age: 1}); Descending :db.userInfo.find().sort({age: -1});
14 、 Inquire about name = zhangsan, age = 22 The data of
db.userInfo.find({name: 'zhangsan', age: 22});
amount to :select * from userInfo where name = ‘zhangsan’ and age = ‘22’;
15 、 Before query 5 Data
db.userInfo.find().limit(5);
amount to :selecttop 5 * from userInfo;
16 、 Inquire about 10 Data after
db.userInfo.find().skip(10);
amount to :select * from userInfo where id not in ( select top 10 * from userInfo );
5、 ... and 、 Delete data
db.collectionsNames.remove( { "borough": "Manhattan" } )db.users.remove({age: 132});By default, the remove() method removes all documents that match the remove condition. Usethe justOne option to limit the remove operation to only one of the matching documents.db.restaurants.remove( { "borough": "Queens" }, { justOne: true }
Here we are , About “MongoDB How to create and delete a database 、 Create delete table 、 Data addition, deletion, modification and query ” That's the end of my study , I hope we can solve your doubts . The combination of theory and practice can better help you learn , Let's try ! If you want to continue to learn more related knowledge , Please continue to pay attention to Yisu cloud website , Xiaobian will continue to strive to bring you more practical articles !
边栏推荐
- Pycharm importing third-party libraries
- NATAPP内网穿透
- Skill review of test engineer before interview
- 章鱼未来之星获得25万美金奖励|章鱼加速器2022夏季创业营圆满落幕
- Colorbar of using vertexehelper to customize controls (II)
- NETCORE 3.1 solves cross domain problems
- How to speed up video playback in browser
- nlohmann json
- Windows starts redis service
- Difference between interface iterator and iteratable
猜你喜欢
STM32 clock system
Postman interface test (I. installation and use)
信息安全实验三 :PGP邮件加密软件的使用
网易云微信小程序
印象笔记终于支持默认markdown预览模式
Information Security Experiment 1: implementation of DES encryption algorithm
超十万字_超详细SSM整合实践_手动实现权限管理
[4G/5G/6G专题基础-147]: 6G总体愿景与潜在关键技术白皮书解读-2-6G发展的宏观驱动力
Jenkins+ant+jmeter use
其实特简单,教你轻松实现酷炫的数据可视化大屏
随机推荐
C language pointer (exercises)
Pytest+request+allure+excel interface automatic construction from 0 to 1 [five nails / flying Book notice]
Storage of data in memory
答案在哪里?action config/Interceptor/class/servlet
Unity uses mesh to realize real-time point cloud (I)
C language pointer (Part 1)
创建一个长度为6的int型数组,要求数组元素的值都在1-30之间,且是随机赋值。同时,要求元素的值各不相同。
信息安全实验三 :PGP邮件加密软件的使用
華為HCIP-DATACOM-Core_03day
Regular matching starts with XXX and ends with XXX
Pytest+request+allure+excel interface automatic construction from 0 to 1 [familiar with framework structure]
C language pointer (Part 2)
【SVN】SVN是什么?怎么使用?
Locust performance test 3 (high concurrency, parameter correlation, assembly point)
Yapi test plug-in -- cross request
Loxodonframework quick start
C language pointer (Part 2)
Netease cloud wechat applet
Dynamics 365Online ApplicationUser创建方式变更
Mysql数据库-锁-学习笔记