当前位置:网站首页>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 .
边栏推荐
- Iso8191 test is mentioned in as 3744.1. Are the two tests the same?
- 光的粒子说(光电效应/康普顿效应)
- How to write a software test report? Here comes the third party performance report template
- Market competitiveness of robot programming education
- 02 MongoDB数据类型、重要概念以及shell常用指令
- @Transactional失效的几种场景
- Zipkin service link tracking
- AS 3744.1标准中提及ISO8191测试,两者测试一样吗?
- The operating mechanism of spectrogram in audio Science
- 工业物联网将取代人工发展吗?
猜你喜欢

Principle and Simulation of switching power supply buck circuit

欧洲家具EN 597-1 跟EN 597-2两个阻燃标准一样吗?
![[graduation season] graduate summary](/img/f6/59134c1dbf70fc809652d925fd528f.jpg)
[graduation season] graduate summary

Door level modeling - learning notes

Leetcode: monotonic stack structure (Advanced)

谈云原生,不得不谈的容器

Pychart shares third-party modules among different projects

Web APIs DOM event foundation dark horse programmer

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

Pycharm不同项目之间共用第三方模块
随机推荐
Building a server monitoring platform with telegraf influxdb grafana
开启创客教育造物学的领域
组件拆分实战
Pycharm setting pseudo sublime color scheme
指针链表
小程序的防抖节流怎么写?
django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3
等保2.0密码要求是什么?法律依据有哪些?
Analysis of future teacher research ability under steam education framework
以自动化赋能转型,飞鹤乳业加速迈向数字化!
使用信号分析器
Pointer linked list
美创入选“2022 CCIA中国网络安全竞争力50强”榜单
Detailed explanation of KVM common commands
Uncertainty principle
软件测试报告怎么编写?第三方性能报告范文模板来了
品达通用权限系统(Day 5~Day 6)
Meichuang was selected into the list of "2022 CCIA top 50 Chinese network security competitiveness"
Does the applet image component not display pictures?
利用ELK 搭建日志分析系统(一)—— 组件介绍