MongoDB (2)-learn about the installation configuration and mongodb installation Configuration
I introduced the general theoretical knowledge of MongoDB. This article will install and use MongoDB on windows and linux. Of course, we will install MongoDB on linux in more cases, after all, the linux server is still mainstream. Of course, for different systems, MongoDB installation and usage are basically the same, so you don't need to care too much about this, we can learn on that platform. Download MongoDB: http://www.mongodb.org/downloads, our website is installed.
1. decompress and install: extract the downloaded MongoDB to the desired path, for example, d: \ mongodb.
2. Create a folder: create a data storage folder, for example, d: \ mongodb \ data \ db; create a log storage folder, for example, d: \ mongodb \ log \ mongodb. log. (Depending on the actual situation, it is not fixed, as long as there is a folder for storing data and logs)
3. Win + R, enter "run", Enter cmd, enter the dos window, run the cd command under d: \ mongodb \ bin, and run: mongod -- dbpath "d: \ mongodb \ data \ db \ "-- logpath" d: \ mongodb \ log \ mongodb. log to run the mongodb service. Note: mongod, dbpath, and logpath keywords. Here we can all view the commands in bin. We use all of these commands. You can use "command-help" to view the parameters.
4. Enter the database: the default port of mongodb is 27017. You can directly use the mongo command to access the database. Then, you can add, delete, modify, and query databases, collections, and documents. However, the command window cannot be closed, or the mongodb service will stop.
5. enable the service together with the computer. In the dos window, enter:
Mongod -- dbpath "d: \ mongodb \ data \ db" -- logpath "d: \ mongodb \ data \ log \ mongodb. log" -- install -- serviceName "MongoDB"
It can also be seen that the service command to start mongodb is loaded into the computer service. The service name is "MongoDB ".
Then START: net start MongoDB
6. Disable the MongoDB service and disable random start:
NET stop MongoDB (disable Service)
Mongod -- dbpath "d: \ mongodb \ data \ db" -- logpath "d: \ mongodb \ data \ log \ mongodb. log" -- remove -- serviceName "MongoDB"
Well, even if this is basically done, of course it is the same in linux. At least the bin command is generic and we need to master some linux operation commands.
Take a look at the common commands:
- Show dbs: displays the Database List
- Use dbname to access the dbname database. It is case sensitive and does not matter if it is not used.
- Show collections shows the set in the database, which is equivalent to the table
The following is a brief introduction to the addition, deletion, modification, and query of databases and their commands. For the rest, let's take a look at the MongoDB system architecture. Let's take a look at the figure. It's quite clear:
Data types that can be stored inside:
- Null indicates a null value or a field that does not exist. {"X": null}
- The boolean type has two values: 'true' and 'false1'. {"X": true}
- The 32-bit integer type is not available. JavaScript only supports 64-bit floating point numbers, so 32-bit integers are automatically converted.
- 64-bit integers do not support this type. Shell uses a special embedded document to display 64-bit integers,
- The number in the 64-bit floating point shell is of this type. The following are all floating point numbers: {"X": 3.1415926} {"X": 3}
- String UTF-8 string can be represented as string type data: {"x": "foobar "}
- The symbol does not support this type. Shell converts the symbol types in the database to strings.
- Object id the Object id is the unique ID of 12 bytes of the document, {"X": ObjectId ()}
- The date type stores the number of milliseconds starting from the standard epoch. Do not store time zone: {"X": new Date ()}
- The regular expression document can contain regular expressions. The regular expression syntax in JavaScript is: {"x":/foobar/I}
- The code document can also contain JavaScript code: {"x": function (){/*...... */}}
- Binary data binary data can be composed of any byte string. But cannot be used in shell.
- Maximum BSON contains a special type, indicating the maximum possible value. Shell does not have this type.
- The minimum value BSON contains a special type, indicating the possible minimum value. Shell does not have this type.
- You can also use the undefined type {"x": undefined} in the undefined document}
- The set or list of array values can be represented as an array: {"x": ["a", "B", "c"]}
- Embedded document documents can contain other documents, or can be embedded into the parent document as values. data can be organized more naturally without having to be stored in a flat structure: {"x ": {"food": "notify "}}
Of course, for more convenient operations on MongoDB, we also provide database connection tools such as PL/SQLdeveloper (connecting Oracle), Mysql Front, Navicat Premium, etc. here we can see MongoVUE, which is very good, take a look at the interface:
Well, we will learn what to add, delete, modify, query, distribution, and load balancing based on the database logic. Let's take a look at the summary below.