Getting started with MongoDB

Source: Internet
Author: User

I. Glossary

1.doc ument is the basic unit of data in MongoDB. It is very similar to rows in the relational database management system (but more complex than rows ).

2. collection can be viewed as a table without a schema.

3. A single MongoDB instance can accommodate multiple independent databases, each of which has its own set and permissions.

4. MongoDB comes with a simple but powerful JavaScript shell. This tool is very useful for managing MongoDB instances and operating data.

5. Each document has a special key "_ id", which is unique in the collection of documents.

2. Doc ument

1.doc ument's key-value is ordered. For example: {"foo": "3", "greeting": "Hello"} and {"greeting": "hello", "foo ": "3"} is different.

2. The key cannot contain \ 0 (Null String). and $. The key starting with _ is retained.

3. The document of MongoDB cannot contain duplicate keys.

Iii. Collection

1. collection is a set of documents. The document in MongoDB is similar to the row in RDBMS, so collection is the table.

2. No Mode

That is to say, the document structure in a collection is different. It can also be a key-value, or a document composed of multiple key-values.

Q: in this case, since a collection can store a variety of documents, do you have to create multiple collections in the actual project? Can I put all the documents in a collection?

A: (1) mixing all kinds of documents in a collection is not only a nightmare for developers or managers. Developers must either make sure that only the desired types are returned each time they execute the query, or let the application that executes the query process all the different types of documents. If you want to query a blog, remove the data containing the author.

(2) it is not cost-effective to query specific documents in a collection. It is much faster to separate multiple collections.

(3) Put documents of the same type in a collection, so that the data is more concentrated. Querying several articles from collections containing only blog articles will consume less disk seek operations than those containing author and article data.

(4) When creating an index, the document will have an additional structure (especially when it is a unique index ). The index is defined according to the set. Placing documents of the same type in the same collection can make the index more effective.

3.

Set NameThe following conditions may be met:Any UTF-8 string

Set name cannot beEmpty string ""

Set NameCannot contain \ 0 characters (null characters), This character indicates the end of the Set Name

Set NameIt cannot start with "system ."This is the prefix reserved for the system set. For example, the system. Users set stores the user information of the database.

The name of the set created by the user cannot contain reserved characters $.

Child set

Organization setAConventionYesSubsets separated by namespaces using the "." Character. For example, an application with the blog function may contain two sets: blog. Posts and blog. authors.

This is only intended to make the organizational structure better. That is to say, the blog set (which does not need to exist here) and Its Subsets have no relationship.

Gridfs is a protocol for storing large files. It uses sub-sets to store file metadata, which is separated from content blocks.

The MongoDB Web Console organizes data in the dbtop section by means of sub-sets

It is a good way to organize data using child sets in MongoDB.

4. Database

Multiple documents in MongoDB form a set. The same set can form a database.. A MongoDB instance can host multiple databases.It is good to store all the data of an application in the same database.

Like a set, a database is identified by a name.

Cannot beNull String ("")

NoContains ''(Space),., $,/, \, and \ 0 (null character)

AllLowercase

Up to 64 bytes

Remember,The database name will eventually become a file in the file system.

Some database names are retained.

Admin

From the perspective of permissions, this is a "root" Database

Local

This data will never be copied and can be usedStorage is limited to any set of local servers.

Config

When MongoDB is usedPartsWhen setting,The Config database is used internally to save information about shards.

Put the database name in front of the Set name to get the fully qualified name of the set and become the namespace.The namespace length cannot exceed 121 bytes. In actual use, it should be less than 100 bytes.

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.