Getting Started with MongoDB basics

Source: Internet
Author: User
Tags mongodump

MongoDB is the old technology represented by NoSQL (without any discriminatory meaning), long time no research, re-study again

1, installation

Download the Unzip installation package

wget Https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.6.5.tgztar-xvzf MONGODB-LINUX-X86_64-3.6.5.TGZMV mongodb-linux-x86_64-3.6.5 MongoDB

Environment variable Configuration

vi/etc/pfofile# last added to MONGO bin directory export path= $PATH:/usr/local/mongodb/bin# Refresh environment variable source/etc/profile# Create a database directory for MongoDB CD Mongodb/mkdir DB

Configuration file (ETC/MONGODB.CNF)

port=27017 #端口 dbpath=/usr/local/mongodb/db #数据库存文件存放目录 logpath=/usr/local/mongodb/mongodb.log #日志文件存放路径 logappend= True #使用追加的方式写日志 Fork=false #不以守护程序的方式启用, that is, not running maxconns=100 #最大同时连接数 noauth=true #不启用验证 #auth =true #启用验证 in the background, After you set administrator permissions, enable the authentication mode Journal=true #每次写入会记录一条操作日志 (you can reconstruct the written data by journal). #即使宕机, at startup Wiredtiger restores data to the last checkpoint point and then replays subsequent journal logs. Storageengine=wiredtiger #存储引擎有mmapv1, Wiretiger, mongorocks#bind_ip = 0.0.0.0 #这样就可外部访问了, such as from Win10 to the MongoDB in a virtual machine
#启动mongodb服务
Mongod--config/etc/mongodb.cnf& #服务已启动 [[email protected] bin]# ps-ef|grep mongodbroot 21246 20823 11:27 pts/0 00: 00:01./mongod--config/etc/mongodb.cnfroot 21268 20823 0 11:27 pts/0 00:00:00 grep--color=auto MongoDB

Without enabling authentication, you can log in to the data directly MONGO the command

2, Initialize Permissions

Add Administrator account

Restarting the MongoDB service, the MONGO command still has access to the database but cannot do anything

After logging in using identity authentication, you are ready to operate: MONGO--port 27017-u "root"-P "root123"-authenticationdatabase "admin"

3, additions and deletions to check and change

After you create a library, use db_name, the database is created automatically after any collection is created.

The collection of additions and deletions to check changes

Db.my_collection. Drop (); Show collections;db.my_collection. Insert ({"user_id": "u001", "Name": "Jack"});d b.my_collection. Insert ({"user_id": "u002", "Name": "Jim", "remark": "Developer"});d B.my_collection.find ({user_id  : "u002"}) db.m_collection. Update ({user_id: "u002"},{$set: {remark: "Senior Developer"}}) Db.my_collection.deleteMany ({  user_id: "u002"})

4, Backup restore

Mongodump-H127.0.0.1:27017 -Uroot-Proot123--authenticationdatabase admin-o/data/backup/Mongodump-H127.0.0.1:27017 -Uroot-Proot123--authenticationdatabase admin-d my_mongodb-o/data/backup/Mongorestore-H127.0.0.1:27017 -Uroot-Proot123--authenticationdatabase admin-d my_mongodb--drop/data/backup/

Backup

Restores

5, typical practical application scenario (own yy out of)

As an example of the blog Park article, an article is nothing more than "author", "title", "Content", "Release Time", "Support number", "Objection number", "Creation Time", "comment", etc. elements
For comments, the comments include "author", "Content", "Support number", "Objection number", "Comment time" and so on, again a sub-document, which is due to part of the article,
If you use a traditional relational database, look at the complexity, to express this information, less than 10 sheets of eight tables, and any one operation is not too simple.
If you use MongoDB, an article, all the information can be represented by a collection, by manipulating the different elements of this collection to achieve, greatly reducing the degree of simplification of data operations.

As follows, is the information of the article itself

Db.article. Insert ({"id": "1", "Author": "A great Man", "title": "Blog Park article", "Content": "A very long article", "Support": "0", "objection": "  0"," create_date ":"2018-6-"});

Add Comments (Add sub-documents below a document)

Db.article.Update({"id": "1"},{$push: {comments: {" id ":" • ","user_name":" Jack "," Content ":" 1 Floor reviews ... "," Support ":"0" ," objection ":"0" ," create_date ":"20180614"        }     }}) Db.article.Update({"id": "1"},{$push: {comments: {" id ":"2",            "user_name":" Mike "," Content ":" 2 floor reviews ... "," Support ":"0" ," objection ":"0" ," create_date ":"20180614"        }     }})

Overall, from the installation to use, or very simple, open source technology do not want to think, the difficulty lies in the operation, high availability, and a variety of unknown pit processing.

Reference:
78765784
Https://www.cnblogs.com/clsn/p/8244206.html
79371316

Getting Started with MongoDB basics

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.