MongoDB database installation details (2). mongodb details

Source: Internet
Author: User
Tags install mongodb md5 hash mongodb server

MongoDB database installation details (2). mongodb details











How to change mongodb in java

Java-based mongodb insert, read, modify, and delete operations

This article describes how to operate MongoDB in Java and how to perform routine database operations in MongoDB. The content of this article is as follows: Step 1: Install MongoDB requires no complicated steps. You only need to check the installation instructions on the official MongoDB website and select an appropriate version based on your operating system. Step 2: Start the MongoDB server. Run the bin folder in mongod.exe (I am using Windows OS) and start the MongoDB server. By default, the server will start port 27017. You need to create and store the data in the/data/db directory during installation. Step 3: Start MongoDB shell you can start MongoBD shell by running the cmd.exe file. Step 4: Use MongoDB to create a database use MongoDB to input the following content in MongoDB shell to create a database named "company. Use company remember that unless you save something in MangoDB, it will not automatically save for you. Use the following command to view available databases. It will show that "company" has not been created. Show dbs; Step 5: save data in MongoDB use the following command to save the employee data to represent a collection and name it employees. Employee = {name: "A", no: 1} db. employees. save (employee) use the following command to view the data in the collection. Db. users. find (); how to operate MongoDB using Java? The following is a simple Java code. You can obtain the mongo-java driver here. It is very simple. You only need to use the following code and repeat the above operations. Package com. eviac. blog. mongo; import java.net. unknownHostException; import com. mongodb. basicDBObject; import com. mongodb. DB; import com. mongodb. DBCollection; import com. mongodb. DBCursor; import com. mongodb. mongo; import com. mongodb. except exception; public class MongoDBClient {public static void main (String [] args) {try {Mongo mongo = new Mongo ("localhost", 27017); DB db = mongo. getDB ("company"); DBCollection collection = db. getCollection ("employees"); BasicDBObject employee = new BasicDBObject (); employee. put ("name", "hanhannah"); employee. put ("no", 2); collection. insert (employee); BasicDBObject searchEmployee = new BasicDBObject (); searchEmployee. put ("no & quot ...... remaining full text>
 
How to Create a mongodb database with a user name and password

I'm so angry. Let's just put it down. Below is a part of my notes on mongodb.
By default, mongoDB user authentication is disabled.
Modify the/etc/cmdd. conf file. By default, any client in mongoDB can connect to port 27017 without authentication. By default, there is no administrator account. By modifying this configuration file, you can change it to permission authentication during login.
If you want to create a user for a database in mongoDB, you must first enter the database and then use the addUser command. You can also set the user to read-only (db. addUser ("jack", "jack", true), and the third parameter to indicate whether the user is a "read-only user ").

To use a super administrator, you must first connect to the admin database and log on to the administrator account, and then connect to other databases to exercise administrator privileges.

User information storage and authentication process

Similarly, MySQL saves system user information in the mysql. user table. MongoDB also saves the username and pwd of the system user in the admin. system. users collection. Pwd = md5 (username + ": mongo:" + real_password ). This is not a problem. Username And: mongo: It is equivalent to adding a salt value to the original password. Even if attackers obtain the md5 hash stored in the database, they cannot simply find the original password from the rainbow table.

Common permission management commands

1. # enter the database admin

Use admin

2. # Add or modify user passwords

Db. addUser ('name', 'pwd ')

3. # view the user list

Db. system. users. find ()

4. # User Authentication

Db. auth ('name', 'pwd ')
If this one returns 1, the authentication is successful. Only after the authentication is successful can the database be operated.

5. # delete a user

Db. removeUser ('name ')

6. # view all users

Show users

7. # view all databases

Show dbs

8. # view all collections

Show collections

9. # view the status of each collection

Db. printCollectionStats ()

10. # view master-slave replication status

Db. printReplicationInfo ()

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.