当前位置:网站首页>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 .
边栏推荐
- 【MySQL】多表连接查询
- 回溯—迷宫问题
- Elk builds log analysis system + Zipkin service link tracking integration
- django. core. exceptions. ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3
- 第一章 Bash 入门
- Adder - Notes
- MSc 307 (88) (2010 FTPC code) Part 2 smoke and toxicity test
- vscode中出现无法在只读编辑器中编辑
- 软件测试报告怎么编写?第三方性能报告范文模板来了
- 英语小记 - 表因果
猜你喜欢

Chapter 1 Introduction to bash

leetcode:494. All methods of adding and subtracting operators to the array to get the specified value

Learning notes of digital circuit (II)

以自动化赋能转型,飞鹤乳业加速迈向数字化!

Open the field of maker education and creation

Does the applet image component not display pictures?

Several important physical concepts

Market competitiveness of robot programming education

Understanding and learning of parental delegation mechanism

歐洲家具EN 597-1 跟EN 597-2兩個阻燃標准一樣嗎?
随机推荐
内卷、躺平与中年危机的相关思考
Zipkin 服务链路追踪
Pychart shares third-party modules among different projects
基于arm5718的Shell脚本参数传递的2种方法
解析STEAM教育框架下未来教师研究能力
从遇见大咖到成为大咖,昇腾AI开发者创享日给开发者带来无限可能
一文告诉你什么是 Kubernetes
MSC 307(88) (2010 FTPC Code)第2部分烟气和毒性测试
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?
leetcode:494. All methods of adding and subtracting operators to the array to get the specified value
02 MongoDB数据类型、重要概念以及shell常用指令
Are the two flame retardant standards of European furniture en 597-1 and en 597-2 the same?
Door level modeling - learning notes
PostgreSQL implements batch update, deletion and insertion
使用信号分析器
How to apply for ASTM E108 flame retardant test for photovoltaic panels?
PyCharm设置仿sublime配色方案
Web APIs DOM-事件基础丨黑马程序员
【毕业季】研究生の毕业总结
Introduction notes to machine learning