当前位置:网站首页>Getting started with mongodb
Getting started with mongodb
2022-07-24 15:02:00 【Monster in the North Sea】
MongoDB brief introduction
MongoDB Is a database based on distributed file storage . from C++ Language writing , For the purpose of WEB Applications provide scalable, high-performance data storage solutions .
MongoDB Is a product between relational and non-relational databases ( Definition or non relational database ), Yes no relational database has the most functions , Most like a relational database . The data structure it supports is very loose , Is similar to the json Of bson Format , Therefore, more complex data types can be stored .
and Redis Compare :
Redis For big data storage, there is no MongoDB major ,Redis It is used for fast reading and writing , therefore Redis Generally used as cache . For storage with large amount of data MongoDB. and MongoDB Low use value . comparison MySql, The cost of building a data server is high .
What situation to use MongoDB:
Large amount of data , Write operations are frequent , Lower value .
Large amount of data , therefore Redis Eliminate .( comparison Redis Reading and writing performance is definitely not comparable )
If you use MySql, Then the cost of building a data server is high , But storing data with low value , Don't bargain . So choose MongoDB.
MongoDB characteristic
Mongo The biggest feature is that it supports a very powerful query language , Its syntax is somewhat similar to that of an object-oriented query language , You can almost implement most of the functionality of a relational database single table query , It also supports indexing data .
It is characterized by high performance 、 Easy to deploy 、 Easy to use , It's very convenient to store data . The main features are :
- For collection storage , Easy to store data of object type .
- Model freedom .
- Support dynamic query .
- Support full indexing , Contains internal objects .
- Support query .
- Support for replication and recovery .
- Use efficient binary data storage , Include large objects ( Video, etc ).
- Automatic processing of debris , To support the scalability of the cloud computing hierarchy .
- Support RUBY,PYTHON,JAVA,C++,PHP,C# multilingual .
- The file storage format is BSON( A kind of JSON An extension of ).
MongoDB Architecture
MongoDB The logical structure of is a hierarchical structure . Mainly by : file (document)、 aggregate (collection)、 database (database) These three parts make up . The logical structure is user oriented , The user to use MongoDB It's the logical structure that's used to develop an application .
- MongoDB Documents (document), Equivalent to a row of records in a relational database .
- Multiple documents make up a collection (collection), The equivalent of a relational database table .
- Multiple sets (collection), Logically organized , Database (database).
- One MongoDB Instance supports multiple databases (database).

MongoDB 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 . |
| 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 . |
| 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 . |
Special instructions :
1、ObjectID There must be , If we set it, use ours , We didn't set up ,MongoDB Just help us generate a .
ObjectID Class is similar to a unique primary key , It can be quickly generated and sorted , contain 12bytes, The meaning is
- The first four bytes identify the creation unix Time stamp , GMT UTC Time , It's later than Beijing time 8 Hours .
- Next 3 Bytes is the machine identity code , Distinguish between different devices
- The next two bytes are determined by the process id form PID( process id)
- The last three bytes are random Numbers

MongoDB Must have one of the documents stored in _id key . The value of this key can be of any type , The default is one ObjectId object
2、 Time stamp
BSON There is a special timestamp type , Not related to ordinary date types .
The timestamp value is one 64 The value of a . among :
front 32 A is a time_t value 【 And Unix A new era (1970 year 1 month 1 Japan ) The number of seconds apart 】
after 32 Bit is an increasing ordinal number that operates in a given second
In a single mongod In the example , The timestamp value is usually unique .
3、 date
Represents the current distance Unix A new era (1970 year 1 month 1 Japan ) Millisecond count . Date types are signed , negative
Express 1970 Year before date .
Window edition MongoDB install
Direct double click msi Start setup , Can be installed .
After installation :
mongo.exe The client side. , Used to connect the service
mongod.exe It is used to start the service
Start the service : First of all, we need a folder for storing data . Default port number 27017
Specify the port to start , Add... After the command -port 8989
Start the client to connect : The default is to connect to the local 27017 port 
Specify the port connection : mongo 127.0.0.1:8989
Docker In the environment MongoDB install
In the production environment, we will The server is deployed in Linux in , Only need window Just connect in
stay Linux Create a virtual machine mongo Containers , The order is as follows :
docker run ‐id ‐‐name mongo ‐p 27017:27017 mongo
stay Window Command line window access login command :
mongo 192.168.200.128 Port number not written default 27017
边栏推荐
- Vector introduction and underlying principle
- 老虎口瀑布:铜梁版小壶口瀑布
- 在哪家证券公司开户最好最安全 如何开户炒股票
- The accuracy of yolov7 in cracking down on counterfeits, not all papers are authentic
- Fraud detection cases and Titanic rescued cases
- The difference and relation among list, set and map
- Can't remember regular expressions? Here I have sorted out 99 common rules
- DDD based on ABP -- Entity creation and update
- Spark Learning Notes (III) -- basic knowledge of spark core
- TypeError: Cannot read property ‘make‘ of undefined
猜你喜欢

ZABBIX administrator forgot login password

AG. DS binary tree -- hierarchical traversal

Error when using Fiddler hook: 502 Fiddler - connection failed

Number of bytes occupied by variables of type char short int in memory

Leetcode · daily question · 1184. distance between bus stops · simulation

Leetcode high frequency question 56. merge intervals, merge overlapping intervals into one interval, including all intervals

The server switches between different CONDA environments and views various user processes

关于构建网络安全知识库方向相关知识的学习和思考

Huawei camera capability
![Rasa 3.x 学习系列-Rasa [3.2.3] - 2022-07-18 新版本发布](/img/fd/c7bff1ce199e8b600761d77828c674.png)
Rasa 3.x 学习系列-Rasa [3.2.3] - 2022-07-18 新版本发布
随机推荐
String application - calculate the longest true prefix of a string
Leetcode-09 (next rank + happy number + full rank)
How vscode debug nodejs
华为相机能力
Learning and thinking about the relevant knowledge in the direction of building network security knowledge base
LeetCode·每日一题·1184.公交站间的距离·模拟
mysql
Wildfire STM32 domineering, through the firmware library to achieve water light
DDD based on ABP -- Entity creation and update
循环结构practice
Video game design report template and resources over the years
ZABBIX administrator forgot login password
Performance test - analyze requirements
Moving the mouse into select options will trigger the mouseleave event processing scheme
AtCoder Beginner Contest 261 F // 树状数组
JS data transformation -- Transformation of tree structure and tile structure
Problem handling of repeated restart during Siemens botu installation
基于ABP实现DDD--实体创建和更新
Attributeerror: module 'distutils' has no attribute' version error resolution
野火stm32霸道,通过固件库实现流水灯