当前位置:网站首页>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 .
边栏推荐
- Arrangement of basic electrical knowledge (II)
- 视频爆炸时代,谁在支撑视频生态网高速运行?
- Market competitiveness of robot programming education
- ambari SSLError: Failed to connect. Please check openssl library versions.
- ELK 搭建日志分析系统 + Zipkin服务链路追踪整合
- 第一个.net core MVC项目
- Analyzing the comprehensive application ability of educational robot
- Arrangement of basic electrical knowledge (I)
- MSC 307(88) (2010 FTPC Code) Part 9床上用品试验
- 以自动化赋能转型,飞鹤乳业加速迈向数字化!
猜你喜欢

One article tells you what kubernetes is

How to write a software test report? Here comes the third party performance report template

sqlserver 数据库之事物使用入门 案例

《性能之巅第2版》阅读笔记(二)--性能观察工具

Leetcode: monotonic stack structure (Advanced)

English语法_形容词/副词3级-比较级_常用短语

La norme européenne en 597 - 1 pour les meubles est - elle la même que les deux normes en 597 - 2 pour les ignifuges?

《性能之巅第2版》阅读笔记(二)--CPU监测

友链须知
![[graduation season] graduate summary](/img/f6/59134c1dbf70fc809652d925fd528f.jpg)
[graduation season] graduate summary
随机推荐
Unity C# 网络学习(十一)——自定义协议生成工具
第一章 Bash 入门
A solution to the inefficiency of setting debug mode in developing flask framework with pychar
使用tensorboard进行loss可视化
第一个.net core MVC项目
05 MongoDB对列的各种操作总结
Are the two flame retardant standards of European furniture en 597-1 and en 597-2 the same?
数字电路学习笔记(一)
Pointer linked list
数字有为,易步到位 华为携“5极”明星产品加速布局商业市场
上线MES系统后,企业发生了这些变化......
MySQL 主从复制、分离解析
iptables防火墙规则和firewalld防火墙规则详解
Detailed explanation of iptables firewall rules and firewalld firewall rules
Chapter 14 AC-DC power supply front stage circuit note I
11_刻意练习精讲
电学基础知识整理(二)
Web APIs DOM-事件基础丨黑马程序员
2021 year end summary and 2022 outlook
Pycharm setting pseudo sublime color scheme