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:
- 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;
- 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