MongoDB Notes (i)

Source: Internet
Author: User
Tags mongodb client

I. MONGODB documents and collections

(1) Documentation

1. The document is the core of MongoDB concept, is essentially a JSON-like Bson format of data, Bson is a class JSON binary format data, can be understood to add some new data types on the JSON, such as the date, Int32,int64 and so on. Bson has the features of light weight, ergodic and high efficiency.

The atomic limit for write operations in 2.MongoDB is at the document level. A single document cannot occupy more than 16M of storage (see different versions), and if it is too big then you have to rethink the table schema design.

3.MongoDB tries to keep the order of key-value pairs when the document is inserted. However, the update operation causes the redistribution of the document memory.

4. Document key naming, _id is the system reserved keywords, he is the default primary key, unique, and cannot be changed. The key cannot contain either a or null character, which is used to denote the end of the key. Cannot start with $, cannot contain. Dot numbers, keys are case-sensitive and cannot be duplicated.

(2) Collection

1. Put together a set of related documents to form a set.

The 2.MongoDB provides some special collections.

3. The collection-named collection name cannot be an empty string, cannot be (a null character), and cannot begin with system.

(3) database

1. Multiple collections make up a database. Each database has separate permissions, one MongoDB instance can host multiple databases, and different databases on the disk can be placed in different folders (with the DIRECTORYPERDB option at startup).

2. The name cannot be an empty string, cannot begin with $, cannot contain. and an empty string, and case sensitivity is recommended in lowercase.


Ii. MongoDB Data type

Bson adds new data types based on JSON, including date, regular expressions, further partitioning of numeric types, and more. 650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M02/99/93/wKioL1lJ50_i4AtwAACGNTc8crw566.jpg "title=" 877b9bf1805f7ec888ec805956aef2c4.jpg "alt=" Wkiol1lj50_i4atwaacgntc8crw566.jpg "/>

1. Numeric Type the MongoDB shell uses the JavaScript shell, and JavaScript only supports 64-bit floating-point numbers, if an int is required to take numberint () and number Long ().

2. The string type is converted to utf-8 encoding by double quotation marks.

3. Binary type can hold any byte composed of strings, picture video, etc.

4. Regular Expressions.

A 5.JavaScript code document can contain arbitrary JavaScript code.

The 6.ObjectId consists of 24 16-character characters, consisting of a total of 12 bytes, used to identify the unique machine.

7. Inline documentation

8. Arrays use square brackets to represent a set of values that can be manipulated as ordered objects (lists, stacks, queues), or as unordered objects (such as collections), which can contain elements of different data types. There are a number of specific operators for the array mongodb, such as $push, $pop, and so on. MongoDB can automatically provide an Multikey index for an array element.


Third, MongoDB Shell

MongoDB Shell = JavaScript interpreter +MONGODB Client

(1) Basic functions

1. Execute the javascript command.

2.MongoDB client-Basic command.

Connect/switch database use Jike;

Data insertion Db.stu.insert (obj);

Data db.stu.find (query);

Data Update db.stu.update (query,obj);

Data deletion db.stu.remove (query);

(2) Tips for use

1.help view Help.

2. Execute the script.

3. Execute the command-line program.

The 4..mongorc.js file is used.

This article from the "12151108" blog, reproduced please contact the author!

MongoDB Notes (i)

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.