MongoDB Basic Concepts

Source: Internet
Author: User

MongoDBIt is a collection-oriented document-based database. Unlike relational databases, there are tables, columns, and rows,MongoDBDatabases are composed of a series of documents. The following describesMongoDBBasic Concepts

 

I,Document

Document isMongoDBThe minimum set unit of a Database. The basic concept is a set unit that is sequentially combined by multiple keys and their associated values.

For example{"One": "Hello World", "two": "hello, MongoDB "}

The concept can be analyzed by multiple keys. The composition of the document is similarHashIn a table, each key corresponds to a record value. In fact, the document can be viewed as a row in a relational database, and each key-value combination can be viewed as the corresponding column in this row. The key represents the column name, the value is the column value.

The document definition has the following requirements:

1And keys cannot contain\ O(Null character), inMongoDBIs used to indicate the end of the string.

2,.And$ EIt has a special meaning. It is used in a specific environment when these two characters are used. You need to make it clear.

3, The following line"_"It is also a reserved character of the system. Be clear when using

4Keys are case sensitive, such{"One": "hello", "one": "Hello "},Indicates different keys.

5And cannot have keys with the same name in the same document. That is, the keys with the same case are invalid in the following documents:

{"One": "Hello", "one": "helloworld "}

6The key value types in the document can be different, such:

{"One": 1, "two": "helloworld", "three": 0.21}

 

 

II,Set

A collection is a set of documents. If a document is similar to a line. The set is equivalent to the table.

 

InMongoDBIn, the set is non-pattern, that is, documents in a set can be varied. In the set, the number of key values of different documents can be different, and the keys can also be different. Different documents can have the same key with different values and types. That is, in the same collection, documents are independent of each other.

Because the set has no mode, it may be difficult to use it in practice. Since there is no mode, the document of the set can be arbitrary, so there is no need for multiple sets. For example, you can create a blog database to store a blog in a collection.Article, Document category, login user, and other data. Of course, in practice, how to operate depends on the situation.

SET command specifications:

1,The Set name cannot be a null string;

2,The Set Name cannot contain\ OCharacter (null ),MongoDBIndicates the end of the Set Name;

3,The Set Name cannot start"System ."Because the prefix is the prefix reserved by the system, suchSystem. Uses, Indicating system user information,System. namespacesStores information about all database sets;

4,The Set Name cannot have$Character.

 

 

III,Child set

A child set can be considered as a name, suchBlog. Users, blog. Author, Here,BlogIt can be a collection or not. Subsets are used to better and more orderly distinguish sets.

IV,Database

Multiple sets form a database. OneMongoDBThe instance can have multiple databases. Each database is completely independent and has its own users and permission information. Even on a disk, the files stored in the database are separated.SQL ServerAnd other databases. The database files of different databases can be stored in different directories. The database naming rules are as follows:

1,Cannot be a null string;

2,Cannot contain''(Space ),,,$,/,\, And\ O(Null character );

3,All lowercase letters are required.

4,Maximum64Bytes.

 

 

Except that the database name cannot have the same name as the existing database retained by the system. For exampleAdmin, local,AndConfig

 

 

Database namespace: the database namespace, which is all the string information obtained by placing the database name before the set. It is a namespace. For exampleBlog. Article. Author. The length of the command space cannot exceed100Characters.

 

 

Chinese problems. When a set or document uses Chinese characters, the following error occurs:

Malformed UTF-8 Character Sequence at offset 33


I checked a lot of information and found that it was not resolved yet. Third-partyAPI. Depressed.

 

Related Article

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.