HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
Whether we learn what database should learn one of the fundamental concepts in mongodb basic concept is that documents, collections, databases, here we introduce one by one.
The following table will help you easier to understand some of the concepts Mongo:
SQL Terminology / Concepts | MongoDB term / concept | explain |
---|---|---|
database | database | database |
table | collection | Database table / Collections |
row | document | Line data recording / Documentation |
column | field | Data Field / Domain |
index | index | index |
table joins | Table joins, MongoDB does not support | |
primary key | primary key | Primary key, MongoDB automatically _id field as the primary key |
By following figure examples, we can more intuitive understanding of Mongo some concepts:
A mongodb can create multiple databases.
The default database MongoDB is "db", the database is stored in the data directory.
A single instance of MongoDB can accommodate multiple independent databases, each with its own set of permissions and different databases are also placed in different files.
"show dbs" command to display a list of all the data.
$ ./mongo MongoDB shell version: 3.0.6 connecting to: test > show dbs local 0.078GB test 0.078GB >
The implementation of "db" command to display the current database object or collection.
$ ./mongo MongoDB shell version: 3.0.6 connecting to: test > db test >
Run "use" command, you can connect to a specific database.
> use local switched to db local > db local >
Examples of the above command, "local" is that you want to link database.
In the next chapter we will explain in detail the use of MongoDB in command.
Database also be identified by name. Database name can be any of the following conditions UTF-8 string.
Some database names are reserved and can directly access these databases have a special role.
Documentation is a key (key-value) of (ie BSON). MongoDB document need not be provided the same field, the same field and does not require the same data type, which is a relational database is very different, MongoDB also very prominent feature.
A simple document examples are as follows:
{"site":"www.w3resource.net", "name":"本教程"}
The following table lists the RDBMS and MongoDB corresponding terms:
RDBMS | MongoDB |
---|---|
database | database |
form | set |
Row | File |
Row | Field |
Joint Table | Embedded document |
Primary key | Primary key (MongoDB provides a key for the _id) |
Database services and clients | |
Mysqld / Oracle | mongod |
mysql / sqlplus | mongo |
have to be aware of is:
Key documents naming convention:
MongoDB is a collection document group, similar to the RDBMS (relational database management system: Relational Database Management System) in the form.
Collection exists in the database, a collection of no fixed structure, which means that you can insert in the collection of data in different formats and types, but usually we insert a set of data will have some relevance.
For example, we can document these different data structures into the collection:
{"site":"www.baidu.com"} {"site":"www.google.com","name":"Google"} {"site":"www.w3resource.net","name":"本教程","num":5}
When the first document into the collection will be created.
The following examples:
db.col.findOne()
Capped collections are fixed-size collection.
It has high performance characteristics and the queue expired (expired in accordance with the order of insertion). Somewhat similar and "RRD" concept.
Capped collections are automatically inserted in order to maintain high performance object. It is ideal for functions and similar standard logging collection of different, you have to explicitly create a capped collection, a collection of the specified size, in bytes. collection of data storage space values assigned in advance.
It is noted that the specified storage size of the database that contains the header information.db.createCollection("mycoll", {capped:true, size:100000})
Information in the database is stored in the collection. They use the namespace system:
dbname.system.*
In MongoDB database namespace <dbname> .system * that contains a variety of system information, special collections (Collection), as follows:
Collection namespace | description |
---|---|
dbname.system.namespaces | List all namespaces. |
dbname.system.indexes | List all indexes. |
dbname.system.profile | It contains the database summary (profile) information. |
dbname.system.users | List all users can access the database. |
dbname.local.sources | It contains a copy of the end (slave) server information and status. |
To modify the system object in the collection has the following restrictions.
In the {{system.indexes}} insert data, you can create an index. But otherwise the table information is immutable (the special drop index command will automatically update the relevant information).
{{System.users}} are modifiable. {{System.profile}} is deleted.
The following table MongoDB several commonly used data types.
type of data | description |
---|---|
String | String. Storing data commonly used data types. In MongoDB, UTF-8 encoded string is legal. |
Integer | Integer values. It used to store values. Depending on the server you are using, it can be divided into 32-bit or 64-bit. |
Boolean | Boolean value. For storing Boolean values (true / false). |
Double | Double-precision floating-point value. For storing floating-point values. |
Min / Max keys | The minimum value and a value BSON (binary JSON) element and the highest value of the relative ratio. |
Arrays | For array or list or store multiple values for a key. |
Timestamp | Timestamp. Modify or add records document the specific time. |
Object | For embedded documents. |
Null | It creates an empty value. |
Symbol | symbol. This data type is substantially equal to the string type, but the difference is that it is generally for the use of special symbols typed language. |
Date | Date Time. UNIX time format used to store the current date or time. You can specify your own date and time: Date object is created, the incoming date information. |
Object ID | Object ID. ID used to create the document. |
Binary Data | Binary data. For storing binary data. |
Code | Tag type. JavaScript code is used to store documents. |
Regular expression | Regular expression type. For storing the regular expression. |