About MongoDB:
MongoDB is a cross-platform, document-oriented database that provides high performance, high availability, and scalability convenience. MongoDB works on the concept of collection and documentation.
MongoDB defaults to no access restrictions, so you can go directly into the database and manipulate the data.
Event background: Recently, the company placed in the mobile room of the two servers equipped with MongoDB database is scanned by the Green Alliance has a loophole, asked us to solve
The solution provided by the Green Alliance is to add any user to the Admin library and enable authentication. But the Green league method is based on Linux, but in fact the principle is similar.
I search the article more on the Internet, to integrate the actual situation of the application of our project, here to record, in order to forget.
Step1: After switching to the bin directory of the MongoDB installation path, perform MONGO login.
SETP2: Use show dbs to directly view the databases that already exist on the system.
Step3: Enter the admin library
STEP4: Create user command as follows:
db.createUser(
{
user
:
"admin"
,
pwd:
"admin123"
,
roles: [ { role:
"userAdminAnyDatabase"
, db:
"admin"
} ]
}
)
STEP5: Enter the system registry (Win+r-->regedit) to find the [hkey_local_machine-->system-->currentcontrolset-->services--> MongoDB] hit "ImagePath" in the value list on the right to add--auth
STEP6: Restart MongoDB service:
STEP7: Re-entry into view existing database discovery does not have permission
STEP8: Authentication, direct authentication prompt failure (because MongoDB users are library-based, you must specify a database before you can authenticate)
STPE9: Enter the admin library, and authenticate, return 1 for authentication success, and can view the database;
But it also leads to a problem, "MongoDB is not available for integrated systems."
Since the integrated system is used directly on the MONGDB, without authentication, the integrated system can no longer use MongoDB after authentication is enabled.
Windows MongoDB Permissions Setting workaround