MongoDB Sixth Lecture

Source: Internet
Author: User
Tags auth mongodb mongodump mongorestore

? MongoDB Start Configuration detailed

1. Startup Item Mongod--help

1.1 Use config profile to start database change port to 8888

mongodb.conf file

DBPath = D:appmongodata

Port = 8888

Startup file

Mongod.exe--config mongodb.conf

Shell file


2. Stop MongoDB Service

1.1ctrl+c keys to close the database

1.2admin Database command Close data

Use admin

Db.shutdownserver ()

? export, import, run-time backup one export, import

1. Export data (interrupt other operations)

Open cmd

Using Mongoexport

-D indicates the library used

-C indicates the table to export

-O indicates the file name to export

-csv to develop the exported CSV format

-Q Filter Export


1.1 The data good foobar in the persons export

mongoexport-d foobar-c Persons-od:/persons.json

1.2 Exporting documents from other host databases

Mongoexport--host 37017

2. Import data (interrupt other operations)

2.1 into the persons file

Mongoimport--db foobar--collection persons--file

Second backup

1. Run-time backup Mongodump

1.1 Export the Foobar database under the service under 27017

Mongodump--host Foobar-o D:/foobar

2. Run-time recovery Mongorestore

2.1 Deleting the original database and restoring it with the database you just exported

Db.dropdatabase ()

Mongorestore--host Foobar-directoryperdb D:/foobar/foobar

3. Lazy Person Backup

MongoDB is a file database, which can actually be backed up by copying files.

? Fsync Lock, data repair

Use of 1.Fsync

Let's look at the simple structure of MongoDB.

2. Lock and Unlock


Db.runcommand ({fsync:1,lock:1});


Db.currentop ()

3. Data Repair

When irreversible disasters such as power outages come, the storage structure of MongoDB causes

Generates garbage data, which is still available after data recovery, which is the database

Provide a self-healing capability. It's easy to use.

Db.repairdatabase ()

? user management, security certification

1. Add a user

1.1 for Admin Add uspcat user and Foobar database Zhang user

Use admin

Db.adduser ("Uspcat", "123");

Use Foobar

Db.adduser ("Zhang", "123");

2. Enable users

Db.auth ("name", "password")

3. Security--auth

Mogod--dbpath D:appmongodata--auth

Mogo localhost:27017

Use Foobar

Db.persons.find ()//Will complain

Non-foobar users cannot manipulate the database, enabling their own users to access

Db.auth ("Zhang", "123")

Database commands cannot be used by users who are not in the admin database

Db.auth ("Zhang", "123")

Show DBS//Will complain

The data in the Admin database is authenticated as an administrator user

4. User delete operation

Db.system.users.remove ({User: "Zhang"});

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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: and provide relevant evidence. A staff member will contact you within 5 working days.