MongoDB Sixth Lecture

Source: Internet
Author: User
Tags auth config 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

MONGO 127.0.0.1:8888

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

--type

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 192.168.0.16--port 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 127.0.0.1 service under 27017

Mongodump--host 127.0.0.1:27017-d 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 127.0.0.1:27017-d 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

Locked

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

Unlock

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 http://www.cnblogs.com/dennisit/archive/2013/02/22/2922906.html

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

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.