当前位置:网站首页>Mongodb implements creating and deleting databases, creating and deleting tables (sets), and adding, deleting, modifying, and querying data
Mongodb implements creating and deleting databases, creating and deleting tables (sets), and adding, deleting, modifying, and querying data
2022-06-26 20:09:00 【1024 Q】
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 )
mongoClear the screen :
clsCheck 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 collectionsDelete 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 );
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 }边栏推荐
- 抖音实战~分享模块~生成短视频二维码
- 黑客用机器学习发动攻击的九种方法
- 西瓜书重温(七): 贝叶斯分类器(手推+代码demo)
- Kubernetes 资源拓扑感知调度优化
- String string is converted to jsonarray and parsed
- 两个文件 合并为第三个文件 。
- MySQL中存储过程的详细详解
- 开户可以在网上开么?能安全吗?
- Project practice 5: build elk log collection system
- Disruptor local thread queue_ Use transprocessor processor and workpool to compare consumption - Notes on inter thread communication 005
猜你喜欢

Project practice 6: distributed transaction Seata

Boot的单元测试

Current limiting design and Implementation

刷新三观的HP-UX系统中的强指针赋值出core问题

When does the mobile phone video roll off?

郭明錤:苹果 AR / MR 头显是其有史以来设计最复杂的产品,将于 2023 年 1 月发布

项目实战六:分布式事务-Seata
MySQL中存储过程的详细详解

Pinda general permission system (day 1~day 2)

Record of user behavior log in SSO microservice Engineering
随机推荐
stm32和电机开发(直流有刷电机和步进电机)
The successfully resolved idea cannot use the log normally after referencing Lombok's @slf4j
460million zongzi were sold in half a year. How big is the "imagination space" of time-honored brands?
MongoDB实现创建删除数据库、创建删除表(集合)、数据增删改查
mongoDB的三种基础备份方法
Record of user behavior log in SSO microservice Engineering
(树) 树状数组
Microservice architecture
String string is converted to jsonarray and parsed
开发者调查:Rust/PostgreSQL 最受喜爱,PHP 薪水偏低
Database SQL statement writing
Logstash安装及使用
8VC Venture Cup 2017 - Final Round C. Nikita and stack
IK word breaker
Basic and necessary common plug-ins of vscade
抖音实战~搜索页面~扫描二维码
Good thing recommendation: mobile terminal development security tool
案例描述:比赛分数管理系统,需要统计历届冠军所得比赛得分,并记录到文件中,其中系统有如下需求:- 打开系统有欢迎界面,并显示可选择的选项- 选项1:记录比赛得分- 选项2:查看往届
Installation and use of filebeat
Solve com mysql. jdbc. exceptions. jdbc4.MySQLNonTransientConnectionException: Could not create connection