MongoDB Add remote user connection

Source: Internet
Author: User
Tags mongodb add

The default MongoDB has just been installed is a direct login without a user's password

> MONGO

MongoDB Shell version:2.2.0

Connecting To:test

> Use admin

Switched to DB admin

> Db.adduser ("Root", "123456")

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/7E/63/wKioL1b-HCiCFKmLAAAgdXEBhxY223.png "title=" 1.png " alt= "Wkiol1b-hcicfkmlaaagdxebhxy223.png"/>

OK, so we set up the Super Administrator's account and password.

The third step, login authentication

> Db.auth ("Root", "123456")

1

Fourth step, query the user who has been added

  > db.system.users.find ()

{"_id": ObjectId ("4f8a558000ab5a9a630c0d31"), "user": "Root", "readOnly": false, "pwd": "b7ba7b1291ce2ec8af3099b8f558 44A1 "}

Fifth step, Telnet user

Exit MONGO, modify the configuration file mongo.dconf

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/7E/63/wKioL1b-HR2CMNsbAAAxGCtlfpw519.png "title=" 2.png " alt= "Wkiol1b-hr2cmnsbaaaxgctlfpw519.png"/>

Modify this to save the restart service

MONGO 127.0.0.1:27017/admin-uroot-p123456 Test Connection-command is to connect to the local admin library

At this point, the super-managed account has been added successfully, the other database is the same operation.

The following post common commands

2. Switch/CREATE Database

Use Yourdb; The current database is created automatically when a collection (table) is created

3. Query all databases

Show DBS;

4. Delete the currently used database

DB. Dropdatabase();

5. Cloning a database from a specified host

DB. Clonedatabase("127.0.0.1"); Clones data from a database on a specified machine to the current database

6. Copy the specified database data from the specified machine to a database

DB. Copydatabase("MyDB", "temp", "127.0.0.1"), copy the native mydb data to the TEMP database

7. Repairing the current database

DB. RepairDatabase();

8. View the database currently in use

DB. GetName();

DB; The DB and GetName methods are the same effect and can query the currently used database

9. Display the current DB status

DB. Stats();

10. Current DB version

DB. Version();

11. View the current DB link machine address

DB. Getmongo();

Collection Aggregation Collection

1. Create a Clustered collection (table)

DB. CreateCollection("Collname", {size:20, Capped:5, max:100});

2. Get a clustered collection with the specified name (table)

DB. GetCollection("account");

3. Get all the aggregation sets of the current DB

DB. Getcollectionnames();

4. Displays the status of all clustered indexes in the current DB

DB. Printcollectionstats();

User-related

1. Add a user

DB. AddUser("name");

DB. AddUser("UserName", "pwd123", true); Add user, set password, read-only

2, database authentication, security mode

DB. Auth("UserName", "123123");

3. Show All current users

Show Users;

4. Delete users

DB. Removeuser("UserName");

Other

1, the error message before the query

DB. Getpreverror();

2. Clear the Error Record

DB. Reseterror();


MongoDB Add remote user connection

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.