Control Architect Help Documentation
×
Menu
Index

Working with Mongo Shell

 
MongoDB provides a shell interface through the Command Processor window that allows administrators and users to execute functions through the Mongo Server for maintaining your physical databases.
 

Create a User Account

This procedure guides you in creating User type accounts on an existing authenticated Mongo Server.
 
Open a Command Process window and log into the Mongo Server using authentication:
 
The login command: "D:\Program Files\MongoDB\Server\bin\mongo.exe" localhost -u admin -p admin --authenticationDatabase admin --authenticationMechanism SCRAM-SHA-1 logs into the Mongo Server that is currently configured for authentication.  Replace the admin password and admin user name with the credentials you created when you enabled authentication.  Do not change the authentication mechanism that is used as Control Architect will only authenticate using this type.  If your Mongo Server was installed to the "C:\" folder path, then replace the 'D' path with your 'C' folder path.  Do not change the authentication database "admin".  Mongo will require authenticating against the [admin] database.
 
Enter the command: "use admin" as shown above to target the [admin] database, which is where all authentication will authenticate against.
 
Enter the command: "show users" as shown above to list the current user accounts configured for this MongoDB physical database.  In the example above you can see 2 existing user accounts that have been created.  The "admin" user has been granted the "root" security access role.  The "user" user account has been granted the "readAnyDatabase" security access role.
 
Create a new user account type
 
Enter the command: db.createUser({user: "user1", pwd: "user1", roles: [ "readAnyDatabase" ] })
 
This will create a new user type account with the User name="user1" and the Password="user1".
 
Enter the command: "show users" to verify the new user account that was created as shown above.
 
To verify the new user account credentials and access, type "exit" to exit the Mongo Shell and log back in using the new user account credentials as shown below.  Type the command text "show dbs" to verify that the user account has access to the required databases.
 
Drop an existing user account
 
Enter the command: db.dropUser("user1") to delete the previously created user account.  Please note that all Mongo Shell commands are case sensitive.
Enter the command: "show users" to verify the deletion of the user account as shown above.
 
Enter the command: "exit" to exit the Mongo Shell and disconnect from the Mongo Server.
 
Use this reference for more information on working with the Mongo Shell.
 

Repair a corrupted Mongo Database

This procedure guides you in repairing a corrupted Mongo Database that exists in a Mongo Server.  Corruption is often the result of an unexpected shutdown or termination of the Mongo Server while database activity was present or during Database migration activities.  It is strongly recommended to take periodic backups of the Mongo database using the Package function.
 
Delete existing Mongo Lock file
If the Mongo Database was not shutdown properly there will be a file named "mongod.lock" in the Mongo physical database folder.  If present this file must first be deleted.  It would be located for example in the database path "F:\MongoData\db".
 
Verify your windows file system is not corrupted
Run Check Disk on the system drive where your MongoDB physical database resides.
 
Right mouse-click on the system drive to view the disk properties.  Select the "Tools" tab and click the "Check" button target to begin scanning your system drive for errors.
 
 
Open a Command Process window and Run As Administrator
 
The Mongo Shell is executed using "C:\Program Files\MongoDB\Server\bin\mongod.exe".  You must enclose the command path in double quotes to encapsulate space characters in the file path.  Adjust the path if the Mongo binaries are located in another folder path.
 
The --dbpath shell command indicates that the Mongo Database is found in the following file path location "F:\MongoData\db".  Again ensure path is enclosed within double quote chars.
The --repair shell command will attempt to repair the physical Mongo Database and all its contained collections, which includes rebuilding all index files.