当前位置:网站首页>02 mongodb data types, important concepts and common shell instructions
02 mongodb data types, important concepts and common shell instructions
2022-06-28 04:05:00 【cui_ yonghua】
Catalog : The basic chapter ( Can solve the problem of 80 The problem of )
01 MongoDB Overview 、 Application scenarios 、 Download mode 、 Connection mode and development history, etc
02 MongoDB data type 、 Key concepts and shell Commonly used instructions
03 MongoDB Various additions to documents 、 to update 、 Delete operation summary
04 MongoDB Various query operations And summary of aggregation operations
05 MongoDB Summarize the various operations of the column
python3 operation MongoDB Various cases of
One . mongo data type
data type | describe |
---|---|
String | character string . Data types commonly used to store data . stay MongoDB in ,UTF-8 The encoded string is legal . |
Integer | Integer values . For storing values . Depending on which server you use , Can be divided into 32 Bit or 64 position . |
Boolean | Boolean value . Used to store Boolean values ( really / false ). |
Double | Double precision floating point value . Used to store floating point values . |
Min/Max keys | Combine a value with BSON( The binary JSON) The ratio of the lowest value of an element to the highest value . |
Array | Used to store an array or list or values as a key . |
Timestamp | Time stamp . Record when the document was modified or added . |
Object | Used for embedded documents . |
Null | Used to create a null value . |
Symbol | Symbol . This data type is basically the same as the string type , But the difference is , It is commonly used in languages with special symbol types . |
Date | Date time . use UNIX Time format to store the current date or time . You can specify your own time and date : establish Date object , Incoming year, month and day information . |
Object ID | object ID. For creating documents ID. |
Binary Data | binary data . Used to store binary data . |
Code | Code type . Used for storage in documents JavaScript Code . |
Regular expression | Regular expression type . Used to store regular expressions . |
1.1 Several important data types :
ObjectId
: It's like a unique primary key , It can be quickly generated and sorted , contain 12 bytes, The meaning is :
- front 4 Four bytes means create unix Time stamp , GMT UTC Time , It's later than Beijing time 8 Hours
- Next 3 Bytes is the machine identity code
- The two bytes immediately followed by the process id form PID
- The last three bytes are random Numbers
character string
: BSON All strings are UTF-8 code .
Time stamp
: BSON The timestamp type is primarily used MongoDB For internal use . In most cases application development , have access to BSON The date type .
The date type
: Represents the current distance Unix A new era (1970 year 1 month 1 Japan ) Millisecond count . Date types are signed , Negative said 1970 Year before date .
Two . Important concepts
2.1 mongo And sql Comparison of terms
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 |
2.2 MongoDB Retained databases
Some database names are reserved , You can directly access these databases for special purposes .
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 serverconfig
: When Mongo Used for sharding Settings ,config The database is used internally , Used to save information about sharding .
2.3 file (document)
A document is a set of key values (key-value) Yes ( namely BSON).MongoDB The document does not need to be set to the same field , And the same fields do not require the same data type , This is very different from a relational database , It's also MongoDB Very prominent characteristics .
Be careful :
Document data structure and JSON Is essentially the same .
All data stored in the collection is BSON Format .
BSON It's a kind of similarity JSON The binary form of storage format , yes Binary JSON For short .
2.4 aggregate (collection)
The collection is MongoDB The document set , Be similar to RDBMS ( Relational database management system :Relational Database Management System) The table in .
The collection exists in the database , Sets have no fixed structure , This means that you can insert different formats and types of data into collections , But usually the data that we insert into a collection has a certain degree of relevance .
Valid collection name
- The collection name cannot be an empty string "".
- The collection name cannot contain \0 character ( Null character ), This character represents the end of the collection name .
- The set name cannot be "system." start , This is the reserved prefix for the system set .
- User-created collection names cannot contain reserved characters . Some drivers do support inclusion in the collection name , This is because some system-generated collections contain this character . Unless you want to access a collection created by this system , Otherwise, don't put it in your name $.
2.5 Several important executables
mongod
: Start the executable of the database instance , As a whole MongoDB The core file in , Responsible for database creation 、 Delete and other management work , Running on the server side , Listen for connection requests from clients .
mongo process
: It's a relationship with mongod Processes interact with each other JavaScript Shell
process , It provides some interactive interface functions for the system administrator to manage the database .
mongodump
: Export data to BSON File format , Backup database , At the same time, these dump File rebuild database . Use mongodump -help
You can view the supported directives .
mongorestore
: Restore backup files .
mongoexport
: Export data to json or csv File format .
mongoimport
: take json or csv Import the file of format into mongo.
mongos
: Process files used in sharding , All query operations on the application side will be analyzed with it first , Then locate the query on a partition , Its monitoring function is similar to mongod The monitoring function of is similar to .
mongofiles
:mongofiles Provides an operation MongoDB Distributed file storage GridFS Command line interface of the system .
mongostat
: Show the currently running mongod or mongos Instance status tool , amount to unix/linux Of vmstat, But the data it provides is only related to the running mongod or mongos Examples related to .
mongotop
: Provides an analysis MongoDB Instance time tracking method on read / write data .
3、 ... and . Commonly used shell Instructions
mongo
Get into mongo Environmental Science ;
db.help()
: Display instruction method and meaning ;show dbs
: Displays a list of all data .( perhaps show databases
Instructions );use Database name
: Database does not exist , Then create the database , Otherwise switch to the specified database ;db.dropDatabase()
: Delete database ( First use Database name
Enter the database to delete );show collections
: Show collection name ( Or use show tables
command )db.createCollection("user_demo")
: Create set user_demo;db.user_demo.drop()
: Delete the collection user_demo.
Be careful : Create set : db.createCollection(name, options)
,
name Is the name of the collection to be created ;
options Is an optional parameter , Specifies the options for memory size and index , The parameters are as follows :
capped
: Boolean type , Optional ) If true, Creates a fixed collection . A fixed set is a set with a fixed size , When it reaches its maximum , It automatically overwrites the earliest document .
When the value is true when , Must specify size Parameters .autoIndexId
:3.2 This parameter is no longer supported .( Optional ) If true, Automatically in _id Field creation index . The default is false.size
:( Optional ) Specifies a maximum value for a fixed set , That is, the number of bytes .
If capped by true, You also need to specify this field .max
:( Optional ) Specifies the maximum number of documents to contain in a fixed collection .
边栏推荐
- 从遇见大咖到成为大咖,昇腾AI开发者创享日给开发者带来无限可能
- 利用ELK 搭建日志分析系统(一)—— 组件介绍
- Pychart shares third-party modules among different projects
- 指针链表
- 门级建模—学习笔记
- 【Linux】【Mysql】ERROR 1698 (28000): Access denied for user ‘root‘@‘localhost‘
- Learning notes of digital circuit (II)
- How to modify a se38 editor theme
- Iso8191 test is mentioned in as 3744.1. Are the two tests the same?
- 基于正点原子stm32的mini板的TFTLCD显示实验
猜你喜欢
谈云原生,不得不谈的容器
ambari SSLError: Failed to connect. Please check openssl library versions.
A solution to the inefficiency of setting debug mode in developing flask framework with pychar
Pycharm不同项目之间共用第三方模块
Staggered and permutation combination formula
2021 year end summary and 2022 outlook
How to apply for ASTM E108 flame retardant test for photovoltaic panels?
Leetcode: monotonic stack structure (Advanced)
Door level modeling - learning notes
Are the two flame retardant standards of European furniture en 597-1 and en 597-2 the same?
随机推荐
English语法_形容词/副词3级 - 比较级
品达通用权限系统(Day 5~Day 6)
leetcode:494. All methods of adding and subtracting operators to the array to get the specified value
Using elk to build a log analysis system (I) -- component introduction
Uncertainty principle
Particle theory of light (photoelectric effect / Compton effect)
leetcode:494.数组中添加加减运算符得到指定值的所有方法
月赛补题
歐洲家具EN 597-1 跟EN 597-2兩個阻燃標准一樣嗎?
GCD maximum common divisor
音频 scipy 中 spectrogram 的运作机制
What is the process of en 1101 flammability test for curtains?
MSc 307 (88) (2010 FTPC code) Part 9 bedding test
单一职责原则
Web APIs DOM-事件基础丨黑马程序员
gcd最大公约数
多项目开发入门,基础设计 类库项目使用
How the uni app automatically switches the requested address according to the environment
A preliminary study of blackbody radiation
Pycharm不同项目之间共用第三方模块