Overview
MongoDB is a very popular non-relational database, as the first article in the introductory series, this article mainly introduces the basic conceptual knowledge of mongdb including naming rules, data types, functions and installation.
Environment:
Os:windows
version:3.4
First, installation
1. Download unzip
Download the corresponding operating system version of the installation package on the official website and unzip it, and I'll use the Windows Environment installation test here.
2. Create the Mongodb\data\db directory in the D drive
3. Initializing data
It is a good idea to add the bin directory to the environment variable before you go to the command directory.
Mongod--dbpath D:\mongodb\data\db
4. Start the service
In the D:\mongodb directory to create the Mongo.config configuration file, the configuration file contents are as follows, only the data and log paths are configured here, the other parameters are temporarily default.
Dbpath=D:\mongodb\data\dblogpath=d:\mongodb\data\log\mongo.log
To add MongoDB to a service startup item
" MongoDB "
Delete Service startup Item command
Mongod "MongoDB"
Start the service
net start MongoDB
Test whether the service is started, enter localhost:27017 in the browser, or the default port is 27017 if no port is specified manually
Ii. Basic Concepts 1. Features
MongoDB does not have some relational databases and common functions, such as connectivity and complex multi-line transactions. Omitting these features is an architectural consideration (for better extensibility) because these two features are difficult to implement efficiently in a distributed system, and in pursuit of performance MongoDB will, as far as possible, hand over some of the processing logic to the client (via driver or application code).
2. function
1. Index
MongoDB supports a common two-level index that allows for a variety of quick queries and provides unique indexes, composite indexes, geospatial indexes, and full-text indexes.
2. Aggregation
MongoDB supports "converged pipelines", where users can create complex aggregations through simple fragments and automatically optimize through the database.
3. Special aggregation types
MongoDB supports the existence of a limited set of time for data that will expire at some point, such as a session. MongoDB also supports fixed-size collections for storing recent data, such as logs.
4. File storage
MongoDB supports a very easy-to-use protocol for storing large files and file meta data.
3. Basic Concepts
- A document is a basic unit of data in MongoDB, similar to a row in a relational database.
- An instance can have multiple databases that are independent of each other, each with its own collection and a collection of tables similar to those in a relational database.
- Each document has a special key "_id", which is unique within the collection to which the document belongs.
- You cannot have duplicate key values for each document. For example {"blog": "News", "blog": "Book"}, in the document key value blog repeat.
- A collection can store mixed documents, that is, different types of documents. But usually do not, in order to facilitate the query and management of general one type of data put a collection.
- MongoDB not only distinguishes between types but also case-sensitive.
4. Naming, rules
Document
- 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 specific environments.
Collection
- Collection name cannot be an empty string
- The collection name cannot contain the \ s character
- The collection name cannot be "system." Beginning
- The reserved character "$" cannot be used in a collection name
Database
- Cannot be an empty string ("").
- The name cannot contain:/, \ 、.、 ', *, <, >,:, |,? , $, and (null characters). It is usually made up of letters and numbers.
- Database names are case-sensitive and lowercase are recommended.
- The database name is up to 64 bytes.
5. Data type
1.null
A field that represents a null value or does not exist
Example: {"x": null}
2. Boolean type
True and flase two values, for example:
{"X": Ture}
3. Values
A 64-bit floating-point value is used by default, and for shaping values, you can use the Numberint class (4-byte signed integer) or the Numberlong class (which represents a 8-character signed integer). Cases:
Default: {"X": 3.14} or {"X": 3}
Specify the Shaping value: {"x": Numberint ("3")} or {"X": Numberlong ("3")}
4. string
{"X": "Foobar"}
5. Date
{"X": New Date ()}
6. Regular Expressions
{"X":/a/b}
7. Arrays
{"X": ["a", "B", "C"]}
8. Inline Documentation
Documents can nest other documents, nested documents as the values of the parent document
{"X": {"a": "B"}}
9. Object ID
The object ID is a 12-byte ID, which is a unique identifier for the document.
ten. binary type
Binary data is a string of any byte
One . Code
Summary
Note: pursuer.chen Blog:http://www.cnblogs.com/chenmh This site all the essays are original, welcome to reprint, but reprint must indicate the source of the article, and at the beginning of the article clearly to the link, otherwise reserves the right to hold responsibility. Welcome to the exchange of discussions |
MongoDB Starter Series (i): Basic Concepts and installation