In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
one。 Brief introduction
MongoDB is a non-relational database (NoSql), which is a powerful, flexible and scalable way of data storage, because MongoDB is a document model with high freedom and flexibility, which can make you smooth in the development process. For Internet applications with large data volume, high concurrency and weak transactions, MongoDB can deal with it freely. The built-in horizontal scaling mechanism of MongoDB provides data processing capacity from a million to a billion levels. There is also support for MapReduce-style aggregation and geospatial indexing.
1.1.Why do you need NoSQL
To put it simply, it is to solve the three high requirements that have emerged in the web2.0 era:
1: the need for high concurrent read and write of database
2: the need for efficient storage and access of massive data
3: the need for high scalability and high availability of databases
Some features of RDB (relational database) tend to become less important in web2.0, such as:
1: database transaction consistency
2: real-time read and write of database
3: complex SQL queries, especially multi-table association queries
1.2.CAP Theorem
CAP theorem, also known as Brewer theorem (Eric Brewer), points out that for a distributed computing system, it is impossible to satisfy the following three points at the same time:
1: strong consistency (Consistency): the system is still consistent after performing an operation. In a distributed system, all users should read the latest value after the update operation is executed successfully. Such a system is considered to have strong consistency.
2: Availability: each operation can always return a result within a certain period of time.
3: partition fault tolerance (Partition tolerance): the system can still accept requests and process them in the presence of a network partition, which means that the network is divided into several isolated areas for some reason, and the regions are not connected to each other
According to the CAP principle, the database is divided into three categories: meeting the CA principle, meeting the CP principle and meeting the AP principle.
1:CA: single point cluster, which meets consistency and availability, and is usually not very powerful in scalability, such as RDB
2:CP: satisfies consistency and partition fault tolerance, and usually does not have very high performance, such as distributed database
3:AP: meets availability and partition fault tolerance, and may generally require less consistency, such as most NoSQL
BASE principle (Basically Available,Soft-state,Eventual consistency)
1: basic availability (Basically Available): the system can basically run and provide services all the time.
2: soft state (Soft-state): the system is not required to maintain a strong consistent state all the time.
3: final consistency (Eventual consistency): the system needs to meet the consistency requirements after a certain time.
1.3. advantages and disadvantages of NoSQL
Advantages
1. Expansion is simple and convenient, especially horizontal scale-out.
(scale-up refers to the use of stronger machines; scale-out refers to the spread of data across multiple machines)
2. Reading and writing is fast and efficient, and most of them are mapped to memory operations.
3. Low cost, using ordinary machines and distributed clusters.
4. The data model is flexible and there is no fixed data model.
Shortcomings of NoSQL
No support for SQL
The existing products are not mature and stable enough, and their functions need to be strengthened.
1.4. characteristics of mongodb
High performance, easy to use, easy to scale, rich in features
Oriented to collective storage and free of mode
Support dynamic query, support javascript expression query
Full indexing is supported, including internal objects
Support for replication and failure recovery
Support for replica set replication and automatic failure recovery
Automatic processing of shards
Use efficient binary data storage, including large objects
The file is stored in BSON (an extension of JSON)
two。 Basic concept
Database
An instance of MongoDB can have one or more independent databases, each with its own collection
Document: is the basic unit of data in MongoDB
Very similar to rows in a relational database system (but much more complex than rows)
Note:
Each document has a special key "_ id", which is unique in the collection in which the document resides, which is equivalent to the
Is the primary key of the table in the database
Collection: is a set of documents
Similar to tables in relational database systems
_ id
Each document has a special "_ id", which is unique in the collection to which the document belongs.
JavaScript shell
MongoDB comes with a powerful JavaScript Shell that can be used to manage or operate MongoDB
A single computer in MongoDB can hold multiple independent databases, each with its own collection and permissions.
MongoDB comes with a brief introduction but powerful JavaScript shell, which is very useful for managing MongoDB instances and manipulating data.
Note: there is no concept of primary foreign key in MongoDB
three。 Rules and data types
3.1. Database name definition rules
1. Cannot be an empty string
2. Must not contain /,\,? , $, spaces, blank characters, etc. Basically you can only use letters and numbers in ASCII
3. Case sensitive, all lowercase is recommended
4. Up to 64 bytes
5. Do not use reserved database names, such as admin,local,config
Note: the database will eventually become a file, and the database name is the name of the file.
3.2. Collection name definition rules
1. Cannot be an empty string
2. Cannot contain the\ 0 character (empty character), which represents the end of the collection name and cannot contain "$"
3. You cannot use "system." At the beginning, this is the prefix reserved for the system collection
3.3. Rules for defining the keys of a document
1. Cannot contain\ 0 character (empty character), which represents the end of the key
2. And "$" are reserved and can only be used in specific circumstances
3. Distinguish between types and case at the same time
4. Keys cannot be repeated.
Note: the key-value pairs of documents are in order, and the same key-value pairs are different documents if they are in different order.
3.4, data type
Examples of data type description
Null represents a null value or undefined object {"x": null}
Boolean true or false: true or false {"x": true}
32-bit integer shell does not support this type. It is converted to 64-bit floating-point numbers by default, or you can use NumberInt classes, such as {"x": NumberInt ("3")}.
64-bit integer shell does not support this type. It is converted to 64-bit floating-point numbers by default. You can also use NumberLong classes, such as {"x": NumberLong ("3")}.
The numbers in 64-bit floating point shell are of this type {"x": 3.14," y ": 3}.
String UTF-8 string {"foo": "bar"}
Symbol shell is not supported. Shell will automatically convert symbol type data in the database into strings.
The unique 12-byte id {"id": ObjectId ()} of the object id document
The number of milliseconds of the date from the standard era {"date": new Date ()}
Regular expression documents can contain regular expressions that follow JavaScript's syntax {"foo": / foobar/i}
The code document can contain JavaScript code {"x": function () {}}
Undefined {"x": undefined} is not defined
A collection or list of array values {"arr": ["a", "b"]}
An embedded document can be used as a value {"x": {"foo": "bar"} of a key in the document
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.