MongoDB basic knowledge and common syntax

Source: Internet
Author: User
Data Structure: Simply put, 1. document is the most basic data organization form in MongoDB. Each document is organized in Key-Value (Key-Value Pair) mode. For example:

Data Structure: Simply put, 1. document is the most basic data organization form in MongoDB. Each document is organized in Key-Value (Key-Value Pair) mode. For example:

Data structure:
1. document is the most basic data organization form in MongoDB. Each document is organized in Key-Value (Key-Value Pair) mode.

For example:

{"Greeting": "Hello World! "}

2. A document can contain multiple Key-Value combinations. Each Value can be of different types, such as String, Integer, and List.

For example:

1. {"name": "huangz ",
2. "sex": "male ",
3. "age": 20}

3. Organize multiple documents to form a collection ). If you compare a document to a row in a relational database, the set is a table in the database ).

In relational databases (such as MySQL), there is always the same row in the same database table. For example, you have a student table with id, name, and ,, age, class, and grade rows, the entire student can only have the same rows.

However, in MongoDB, the content format can be very casual. In a collection, store multiple documents with different keys and different types. For example, you can store them in a student set, there are documents in the following format:

In this student set, every document is not required to have the same Key and type.

1 .{
2. "name": "huangz ",
3. "age": 20,
4. "sex": "male"
5 .}
6.
7 .{
8. "name": "jack ",
9. "class": 3,
10. "grade": 3
11 .}

To sum up, MongoDB organizes data as follows:

Key-Value Pair> document> set> Database


In addition, in MongoDB (excluding GridFS), the size of a single document cannot exceed 4 mb (version> = 1.7 is 16 MB ).

The Key follows the following rules:

The naming rules of a set are similar to those of a document. Remember that

  • The system set is retained.
  • In addition, ". "Number is allowed in the set, and they are used as subcollections. For example, if you have a blog set, you can use a blog. title, blog. content or blog. author helps you better organize collections.

    By organizing multiple sets, a database is formed ). A single MongoDB instance can use multiple databases. Each database operates independently and has independent permissions. The data of each database is stored in different files separately.

    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.