MongoDB step-by-step [feature] for document storage

Source: Internet
Author: User
. JSON-style file and dynamic mode for document storage make MongoDB simple and powerful. SchemaDesign: Schema Design in MongoDB is very different from traditional DBMS. However, Schema is very important and the first step to establish an application. In traditional data models, an independent use case is provided for an object-link model.

. JSON-style file and dynamic mode for document storage make MongoDB simple and powerful. Schema Design: Schema Design in MongoDB is very different from traditional DBMS. However, Schema is very important and the first step to establish an application. In traditional data models, an independent use case is provided for an object-link model.

 

.


Document Storage

JSON-style files and dynamic modes make MongoDB simple and powerful.

 

Schema Design: Schema Design


In MongoDB, the Schema design is very different from the traditional DBMS. However, Schema is very important and the first step to establish an application.

In traditional data models, an independent use case for an object-link model is conceptually correct. This is a normal third paradigm, but this usually deviates from your performance considerations. In MongoDB, Schema design is not only a case for data modeling. Based on the most common use cases, we have optimized the Schema design, which has advantages and disadvantages-the use cases are usually high-performance. However, there is a bias that Schema may make some dynamic queries less elegant than the relational model.

When designing a Schema, consider the following:

1. When will we embed data and links (see below )? Our decision here is to explain the answer to the second question.

2. How many sets do we have? What are they?

3. When do we need atomic operations? These operations can be performed within the BSON document scope, but not all documents.

4. What indexes will we create to make queries and updates faster?

5. How can we split it? What is a partition key?

Embedding and Linking: Embedding and Linking

When designing a MongoDB Schema, a key issue is when to embed and when to link. Embedding is embedded with nested objects and arrays in BSON documents. server space and links are references between documents.

There is no join in MongoDB-it is very difficult to perform distributed join in the 1000 server cluster. Embedding is a bit like "prejoined" data.

It is very easy for the server to process operations in a document. In the U.S. space, these operations can be quite rich. In contrast, the client application must be processed, and the application processes the document by releasing a subsequent query.

In general, if there is a "include" Relationship between entities, you should choose embedding. If you do not use a connection, duplicate data is generated. Select a link.

Collections: Set

Integration in MongoDB is similar to a table in a relational database, Hong Kong Space. Each collection contains documents. As mentioned above, these files can be quite rich. Fields in a set document are not explicitly declared. However, it comes from a Schema designer's concept about what fields will be and how the documents are structured in the set. MongoDB does not need to have the same structure of documents in the set. However, in practice, most collections are highly homogeneous. We can avoid this as long as we are willing. For example, when adding a new field, an "alter table" style operation is not necessary in this case.

Atomic Operations: Atomic Operations

Some problems require the ability to perform atomic operations. For example, simply add a counter to a case requiring atomic operations. MongoDB can also perform more complex operations, as shown in the following pseudo code:

Atomically {if (doc. credits> 5) {doc. credits-= 5; doc. debits + = 5 ;}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.