当前位置:网站首页>Mongodb (compare relational database, cloud database, common command line, tutorial)
Mongodb (compare relational database, cloud database, common command line, tutorial)
2022-07-28 08:56:00 【YF-SOD】
Catalog
db.createCollection("collectionName")
( Insert )db.collectionName.insert([{name:'yf',age:18},{name:'mm',age:null}])
( lookup )db.collectionName.find({age:{$gt:3,$lte:5}})
db.collectionName.find({$or:[{name:'yf'},{age:18}]})
db.collectionName.find({name:/^a.*c$/})
db.collectionName.find({},{name:0})
db.collectionName.find({}).sort({age:1})
db.collectionName.find().limit(3).sort({age:1})
db.collectionName.find().skip(2)
db.collectionName.find().count()
db.collectionName.distinct('name')
( modify )db.collectionName.update({name:'yf'},{$set:{age:16}},{upsert:true})
db.collectionName.updateMany({name:'abc'},{$inc:{age:100}})
( Delete )db.collectionName.remove({name:'a'},{justOne:true})
MongoDB
A database based on distributed file storage . Products between relational and non relational databases , Non-relational databases are the most versatile , Most like a relational database .
contrast RDBMS( The term )
RDBMS( Relational database management system ) And MongoDB Corresponding term :
| SQL The term / Concept | MongoDB The term / Concept | explain / explain |
|---|---|---|
| database | database | database |
| table | collection | Database table / aggregate |
| row | document | Data record row / file |
| column | field | Data field / Domain |
| index | index | Indexes |
| table joins | Table joins ,MongoDB I won't support it | |
| primary key | primary key | Primary key ,MongoDB Automatically put _id Field sets the primary key |
Through the following example , We can also see it more visually Mongo Some of the concepts in :

Official website installation
Install MongoDB Community Edition — MongoDB Manual
MongoDB Cloud database
Keep database name
By default, there is a database that can be accessed directly .
- admin: From a rights perspective , This is a "root" database . Add a user to the database , This user automatically inherits permissions for all databases . Certain server-side commands can only be run from this database , Such as listing all the databases or shutting down the server .
- local: This data will never be copied , Can be used to store any collection limited to a single local server
- config: When Mongo Used for sharding Settings ,config The database is used internally , Used to save information about sharding .
Common command line
help
Check the command prompt .
Database operation
use dbname
Create a database named dbname( Usually lowercase )
show dbs
Display all databases ( If there is no set in the database, it will not be displayed use The created database will not display )
db.dropDatabase()
Delete the current database .
db.stats()
View the currently used database information , Including the name 、 size 、 How many sets are there .
db.getMongo()
View the address of the current database link .
db.getName()
View the database name currently in use
db.version()
Check the database version
Set operations
db.createCollection("collectionName")
Create set collectionName.
db.getCollectionNames()
View the names of all sets in the current database .
db.printCollectionStats()
View the information of all sets under the currently used database , Including the name 、 size 、 How many pieces of data .
file ( data ) operation
( Insert )db.collectionName.insert([{name:'yf',age:18},{name:'mm',age:null}])
stay colletionName Insert multiple pieces of data under the set ( When colletionName When the set does not exist , The collection will be created and the data will be inserted ).
( lookup )db.collectionName.find({age:{ $gt:3,$lte:5}})
Show colletionName Gather all age Greater than 3 Less than or equal to 5 The data of . When not writing , To display all data .$gt Greater than ,$lt Say less than ,$gte Is greater than or equal to ,$lte Less than or equal to .
db.collectionName.find({$or:[{name:'yf'},{age:18}]})
Show colletionName Set below name:'yf' perhaps age:18 The data of .
db.collectionName.find({name:/^a.*c$/})
Show colletionName Gather all name With a Begin with c Data at the end .
db.collectionName.find({},{name:0})
Show colletionName Set all data under ,name Field not displayed .
db.collectionName.find({}).sort({age:1})
Show colletionName Collect all the data and follow age In ascending order ,-1 Representation of descending order , The default is 0 Don't order .
db.collectionName.find().limit(3).sort({age:1})
Show colletionName Set according to age The first three data after the ascending order of ( Be careful sort Write limit Before or after sorting, data is retrieved ).
db.collectionName.find().skip(2)
Skip the former 2 Data , Show colletionName Gather all other data .
db.collectionName.find().count()
Show colletionName How many pieces of data are there in the set .
db.collectionName.distinct('name')
Show colletionName Gather all name Corresponding value ( duplicate removal After ).
( modify )db.collectionName.update({name:'yf'},{$set:{age:16}},{upsert:true})
take colletionName Gather the first name:'yf' The data of age Set to 16,upsert:true It means to create a piece of data if it is not found ( This parameter cannot be written , The default is false).
db.collectionName.updateMany({name:'abc'},{$inc:{age:100}})
take colletionName Gather all name:'abc' The data of age increase 16.
( Delete )db.collectionName.remove({name:'a'},{justOne:true})
take colletionName Gather the first name:'a' Data deletion ,justOne:true Indicates that only one ( The default is false, Optional ).
course
边栏推荐
- Export SQL server query results to excel table
- Customer first | domestic Bi leader, smart software completes round C financing
- The cooperation between starfish OS and metabell is just the beginning
- After summarizing more than 800 kubectl aliases, I'm no longer afraid that I can't remember commands!
- 【软考软件评测师】2013综合知识历年真题
- 49 opencv deep analysis profile
- 竞赛:糖尿病遗传风险检测挑战赛(科大讯飞)
- PHP Basics - PHP uses mysqli
- 阿里技术四面+交叉面+HR面,成功拿到offer,双非本科进不了大厂?
- MySQL怎么查询可以同时判断多个字段值是否存在
猜你喜欢

Round C financing has been completed! Smart software leads domestic Bi ecological empowerment, and products and services are a step forward

阿里技术四面+交叉面+HR面,成功拿到offer,双非本科进不了大厂?

竞赛:糖尿病遗传风险检测挑战赛(科大讯飞)

Huid learning 7: Hudi and Flink integration

Introduction of functions in C language (blood Book 20000 words!!!)

Image batch processing | necessary skills

Do you know the five minute rule and the ten byte rule?

ciou损失

看完这12个面试问题,新媒体运营岗位就是你的了

No one wants to tell the truth about kubernetes secret
随机推荐
Smart software completed round C financing, making Bi truly "inclusive"
Starfish Os打造的元宇宙生态,跟MetaBell的合作只是开始
Machine learning how to achieve epidemic visualization -- epidemic data analysis and prediction practice
Pyflink connecting iceberg practice
谷歌 Material Design 的文本框为什么没人用?
Alibaba technology has four sides + intersection +hr, and successfully got the offer. Can't double non undergraduate students enter the big factory?
为什么 ThreadLocal 可以做到线程隔离?
C轮融资已完成!思迈特软件领跑国内BI生态赋能,产品、服务竿头一步
Shell编程规范与变量
NDK 系列(6):说一下注册 JNI 函数的方式和时机
postgresql查询【表字段类型】和库中【所有序列】
[cloud computing] several mistakes that enterprises need to avoid after going to the cloud
阿里巴巴内部面试资料
Vk1620 temperature controller / smart meter LED digital display driver chip 3/4-wire interface with built-in RC oscillator to provide technical support
Slice function of JS handwriting function (thoroughly understand the header but not the footer)
[activity registration] User Group Xi'an - empowering enterprise growth with modern data architecture
I use SqlClient normally, and dlink submission will report this error. What should I do?
Oracle SQL problems
竞赛:糖尿病遗传风险检测挑战赛(科大讯飞)
How to configure phpunit under window