MongoDB Linux installation

Introduction
MongoDB[1] is a database based on distributed file storage. Written in C++ language. It aims to provide scalable high-performance data storage solutions for WEB applications.
mongoDB
mongoDB
MongoDB[2] is a product between relational databases and non-relational databases. It is the most feature-rich and most similar to relational databases among non-relational databases. The data structure it supports is very loose and is a JSON-like bson format, so it can store more complex data types. The biggest feature of Mongo is that the query language it supports is very powerful. Its syntax is somewhat similar to the object-oriented query language. It can almost realize most functions similar to single-table query in relational databases, and it also supports indexing of data. [3

Features
It is characterized by high performance, easy deployment, easy use, and it is very convenient to store data. The main features are:
*Oriented to collection storage, easy to store data of object type.
mongodb cluster reference
mongodb cluster reference
* schema free.
* Support dynamic query.
* Supports full indexing, including inner objects.
* Support query.
* Supports replication and failover.
* Use efficient binary data storage, including large objects (like videos, etc.).
* Automatically handle fragmentation to support scalability at the cloud level.
* Support RUBY, PYTHON, JAVA, C++, PHP, C# and other languages.
*The file storage format is BSON (an extension of JSON).
*Available via web.

Install MongoDB on Linux
1. Download Mongodb for Linux
Download address: https://www.mongodb.org/dl/linux/x86_64
2. Unzip the MongoDB
tar -zxvf mongo compressed file

3. Create a data log folder (data: database folder, the file The folder will not be automatically generated. log: create a log folder, when running MongoDB as a service, you must specify the log path, --logpath xxx/xxx.log)
4. Execute the MongoDB
command./mongod --dbpath /data/db - -logpath /usr/local/mongodb/log/mongo.log --fork
5. Execute the MongoDB command
./mongo This operation is used to enter mongo
show dbs to view all current databases
6. Add an administrative user (mongoDB does not have an invincible user root, only A user who can manage users userAdminAnyDatabase)
//Create a user before Mongo 3.0
db.addUser('tank','test');
//Switch to the admin database
use admin

//After 3.0, create a user under admin
db.createUser(
  {
    user: "admin",
    pwd: "reformerhz",
    roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
  }
)
7. After adding the administrative user, close MongoDB, and use the permission method to open MongoDB again. Be careful not to use kill to kill the mongodb process directly. (If you do, go to the data/db directory and delete the mongo.lock file), you can use db.shutdownServer() to shut down.
8. Start MongoDB with permission
//Mongo
command./mongod --dbpath /data/db --logpath /usr/local/mongodb/log/mongo.log --fork --auth
9. User authentication is required at this time
//Mongo command, returning 1 means successful
db.auth("user","pwd")
10. After verification, it still can't do the operation, because admin only has user management authority, create users below, users follow the library, created users Both are.
//Mongo command
use you-db_name #Select database
//Create user
db.createUser(
{
   user: "name",
   pwd: "xxx",
   roles: [
      { role: "
   ]
}
)
11. Enter the database to which the user belongs and perform authentication, then you can operate the database
use you_db_name #Select the database
db.auth("name","xxx")#User authentication
12. Create DB
use you_db_name
13. Create collection
db.createCollection("CollectionName")
Note: The created database mydb does not exist in the list. To display the database, it needs to be inserted into at least one file.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326514122&siteId=291194637