MongoDB lecture 6

Source: Internet
Author: User
Tags mongodump mongorestore
? MongoDB STARTUP configuration explanation 1. startup Item mongod -- help1.1 use config configuration file to start Database Change port to 8888mongodb. conf file dbpathD: app1_dataport8888startup file mongod.exe -- configmongodb. confshell file mongo127.0.0.1: 88882. Stop mongoDB Service 1

? MongoDB STARTUP configuration details 1. startup Item mongod -- help 1.1 Use the config configuration file to start the database and change the port to 8888 mongodb. conf file dbpath = D: \ app \ Startup data port = 8888 Startup File mongod.exe -- config mongodb. conf shell file mongo 127.0.0.1: 8888 2. stop mongoDB Service 1

? MongoDB STARTUP configuration details

1. startup Item mongod -- help

1.1 Use the config configuration file to start the database and change the port to 8888.

Mongodb. conf file

Dbpath = D: \ app \ upload data

Port = 8888

Start File

Mongod.exe -- config mongodb. conf

Shell File

Mongo 127.0.0.1: 8888

2. Stop mongoDB Service

1.1 ctrl + c can close the database

1.2admin database command to close data

Use admin

Db. shutdownServer ()

? Export, import, and backup during running 1. Export and Import

1. Export data (interrupt other operations)

Open CMD

Use Export

-D indicates the library used

-C: Specify the table to be exported.

-O indicates the file name to be exported.

-Use csv to specify the exported csv format.

-Q filter and export

-- Type

1.1 export the persons in the foobar

Export export-d foobar-c persons-oD:/persons. json

1.2 export documents of other host Databases

Mongoexport -- host 192.168.0.16 -- port 37017

2. import data (other operations are interrupted)

2.1 to the persons file

Export Import -- db foobar -- collection persons -- file d:/persons. json

Secondary backup

1. Backup mongodump during running

1.1 export the foobar database under 27017 under 127.0.0.1 Service

Mongodump -- host 127.0.0.1: 27017-d foobar-o d:/foobar

2. Resume mongorestore at runtime

2.1 Delete the original database and restore it with the exported Database

Db. dropDatabase ()

Mongorestore -- host 127.0.0.1: 27017-d foobar-directoryperdb d:/foobar

3. Lazy backup

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

? Fsync lock, data repair

1. Use of Fsync

Let's take a look at the simple structure of mongoDB.

2. Lock and unlock

Lock

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

Unlock

Db. currentOp ()

3. Data repair

When an irreversible disaster such as power failure comes, it is caused by the storage structure of mongodb.

Junk data is generated. After data recovery, the junk data still exists. This is a database.

Provides a self-healing capability, which is easy to use.

Db. repairDatabase ()

? User Management and Security AuthenticationHttp://www.cnblogs.com/dennisit/archive/2013/02/22/2922906.html

1. Add a user

1.1 Add the zhang cat user and the zhang user of the foobar database to the admin

Use admin

Db. addUser ("uspcat", "123 ");

Use foobar

Db. addUser ("zhang", "123 ");

2. enable the user

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

3. Security Check-auth

Mogod -- dbpath d: \ app \ parse data -- auth

Mogo localhost: 27017

Use foobar

Db. persons. find () // an error is reported

Non-foobar users cannot operate databases, and only their own users can access the database.

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

Non-admin database users cannot use database commands

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

Show dbs // an error is reported

Data in the admin database is authenticated as administrator users

4. User Deletion

Db. system. users. remove ({user: "zhang "});

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.