MongoDB Basic Operations

Source: Internet
Author: User

I. MongoDB INTRODUCTION

MongoDB installation without adding any parameters, by default, there is no permission authentication, logged on users can be arbitrary operation of the database and can access the database remotely, need to start with the --auth parameter.

When the installation is complete, MongoDB has an admin database By default, at this time the admin database is empty, there is no record permission related information. When admin.system.users is not available to a user, even if the--auth parameter is added when Mongod is started, if no user is added to the admin database, no authentication can be done at this time (whether or not the--auth parameter is started) until a user is added to the admin.system.users.

Precautions:

    1. MongoDB access is divided into connections and permissions validation, even if the--auth parameter is started or the database can be connected without a user name, but there is no permission to do anything;
    2. The user name in the Admin database can manage all databases, and users in other databases can only manage the database in which they reside.
Two. MongoDB common Operation 1. Add/Remove Users

1.1 Enter admin to create an admin account

Use admin db.adduser ("test","test "

1.2 Create a program to use the user in the database you need to use

Use test db.adduser ("test","test")    #默认拥有读写权限 db.adduser ("test","test" , True)    
2. Backup/Restore Database

2.1 Backing up the database

mongodump-d Database    #database为要备份的数据库名字

A dump directory is automatically created in the current directory to hold the backed up files.

2.2 Restoring a previously backed up database

mongorestore-d Database dump/*    

2.3 Deleting a database

Use database   db.dropdatabase ()
3. Import/Export Data

3.1 Exporting data from MongoDB (JSON, CSV)

1 mongoexport-d database_name-c collection_name-o test.dat2 mongoexport-d database_name-c Collection_name-o Test.json    #  exported to JSON format 3 mongoexport-d database_name-c collection_ Name--csv-o test.csv    #  export to CSV format

3.2 Importing JSON data

1 mongoexport-d database_name-c collection_name test.dat2 mongoexport-d database_name-c Co Llection_name Test.json    #  two different ways to
Three. MONGO Visualization tool

According to the personal experience, I think it is Robomongo more useful, and installation and use is not complicated.

MongoDB Basic Operations

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.