1. Introduction:
MongoDB is written by the C + + language and is an open source database system based on distributed file storage. In the case of high load, adding more nodes can guarantee the performance of the server. MongoDB is designed to provide scalable, high-performance data storage solutions for Web applications.
MongoDB stores data as a document and data structures consist of key-value (key=>value) pairs. A MongoDB document is similar to a JSON object. Field values can contain other documents, arrays, and array of documents.
2. Main Features
- MongoDB provides a document-oriented storage that is simple and easy to operate.
- You can set the index of any property in the MongoDB record (for example: Firstname= "Sameer", address= "8 Gandhi Road") for faster sorting.
- You can create data mirroring either locally or on the network, which makes MongoDB more extensible.
- If the load increases (requiring more storage space and greater processing power), it can be distributed across other nodes in the computer network which is called a shard.
- The MONGO supports rich query expressions. Query directives use a JSON-style tag to easily query objects and arrays embedded in the document.
- MongoDb uses the update () command to implement a replacement of the completed document (data) or some specified data fields.
- The map/reduce in MongoDB is primarily used for batch processing and aggregation of data.
- Map and reduce. The map function calls emit (Key,value) to traverse all records in the collection, passing key and value to the reduce function for processing.
- The map function and the reduce function are written in JavaScript and can be executed with the Db.runcommand or MapReduce command.
- Gridfs is a built-in feature in MongoDB that can be used to store a large number of small files.
- MongoDB allows you to execute scripts on the server, write a function in JavaScript, execute directly on the server, or store the definition of the function on the server, next time you call it directly.
- MongoDB supports a variety of programming languages: ruby,python,java,c++,php,c# and many more languages.
- MongoDB installation is simple.
3.MongoDB Concept Analysis
No matter what database we learn, we should learn the basic concepts, the basic concept in MongoDB is a document, a collection, a database, we introduce each one.
The following table will help you understand some of the concepts in MONGO more easily:
SQL Terminology/Concepts |
MongoDB Terminology/Concepts |
Explanation/Description |
Database |
Database |
Database |
Table |
Collection |
Database Tables/Collections |
Row |
Document |
Data record lines/documents |
Column |
Field |
Data fields/Fields |
Index |
Index |
Index |
Table joins |
|
Table connection, MongoDB not supported |
Primary key |
Primary key |
Primary key, MongoDB automatically sets the _id field as the primary key |
the show DBS command can display a list of all data.
Execute the "DB" command to display the current database object or collection.
You can connect to a specified database by running the "use" command.
>Show Dbsadmin0. 000gbdjango_test0. 002GBlocal0. 000GBstock0. 002GBtest0. 037GB>dbtest> Usestockswitched toDB Stock>Dbstock>
View Code4. Collection
A collection is a MongoDB document group, similar to a table in an RDBMS (relational database management system: Relational databases Management systems).
The collection exists in the database, the collection does not have a fixed structure, which means that you can insert data in different formats and types on the collection, but usually we have some relevance to the data that we insert into the collection.
5. Documentation
A document is a set of key-value (Key-value) pairs (that is, Bson). MongoDB documents do not need to set the same field, and the same field does not require the same data type, which is very different from the relational database, is also a very prominent MongoDB features.
An example of a simple document is as follows:
{"site":"www.runoob.com","name":"rookie Tutorial"}
The following table lists the terms that the RDBMS corresponds to MongoDB:
RDBMS |
MongoDB |
Database |
Database |
Form |
Collection |
Yes |
Document |
Column |
Field |
Table Union |
Embed a document |
Primary key |
Primary KEY (MongoDB provides key for _id) |
Database Services and clients |
Mysqld/oracle |
Mongod |
Mysql/sqlplus |
Mongo |
It is important to note that:
- The key/value pairs in the document are ordered.
- The values in the document can be not only strings in double quotes, but also several other data types (even the entire embedded document).
- MongoDB distinguishes between type and case.
- MongoDB documents cannot have duplicate keys.
- The key of the document is a string. In addition to a few exceptions, keys can use any UTF-8 character.
Document key naming specification:
- The key cannot contain a/s (null character). This character is used to denote the end of a key.
- . and $ have special meaning and can only be used in certain circumstances.
- Keys that begin with the underscore "_" are reserved (not strictly required).
6.MongoDB Data types
The following table is a few of the data types commonly used in MongoDB.
Data Type |
Description |
String |
String. Data types commonly used to store data. In MongoDB, the UTF-8 encoded string is legal. |
Integer |
Integer value. Used to store numeric values. Depending on the server you are using, it can be divided into 32-bit or 64-bit. |
Boolean |
Boolean value. Used to store Boolean values (True/false). |
Double |
Double-precision floating-point value. Used to store floating-point values. |
Min/max keys |
Compares a value to the lowest and highest value of a BSON (binary JSON) element. |
Arrays |
Used to store an array or list or multiple values as a single key. |
Timestamp |
Time stamp. Record when the document was modified or added. |
Object |
Used for inline documents. |
Null |
Used to create a null value. |
Symbol |
Symbol. The data type is basically the same as the string type, but unlike it, it is typically used in languages with special symbol types. |
Date |
Date time. Use the UNIX time format to store the current date or time. You can specify your own datetime: Create a Date object and pass in the month-date information. |
Object ID |
The object ID. The ID used to create the document. |
Binary Data |
Binary data. Used to store binary data. |
Code |
The code type. Used to store JavaScript code in a document. |
Regular expression |
The regular expression type. Used to store regular expressions. |
MongoDB Learning Tutorials (1)