REPL : related to replica set such as initial sync or heartbeats
REPL_HB : replica set heartbeats
ROLLBACK : rollback operations
SHARDING : sharding operations
STORAGE : storage activities
JOURNAL : journaling activities
WRITE : update commands
To know the information about the verbositylevel for each of the section displayed in the mongod logs use the following command :
db.LogComponents()
db.LogComponents()
The verbosity levels mentioned in the output of the above command :
-1 : Inherit from parent
0 : Default verbosity. to include informational messages
1-5 : increases the verbosity level to include Debug messages
To get the logs using the mongo shell :
db.adminCommand({ getLog: 'global' })
db.adminCommand({ getLog: 'global' })
Another method to view the logs is using the below command :
tail -f /data/db/mongod.log
tail -f /data/db/mongod.log
To set the verbosity level for a particular section, for example index use the below command :
db.setLogLevel(0, 'index')
db.setLogLevel(0, 'index')
Information present in the debug message in the mongod logs :
Lorem ipsum
Profiling the Database
Need for the profiler in the mongod process :
Though many of the information are displayed in the logs of the mongod process, there are no information regarding executionstats, the direction of an index used by a query, rejectedplans etc…
There is a way to add the above info to the mongod logs but it shouldnot be done. Because of the fact that the logs provide the administrators with the operationallogs about an instance or process so that they can find any errors, warnings, or any interesting informational messages.
Profilers are enabled on database level, so each database will have a profile.
All the information regarding the profiling is stored in a seperate collection named system.profile
When the profiler is enabled it collects the data about CRUD operations, Administrative operations and Configuration options.
The profiler has three settings :
0 : The profiler is off and does not collect any data. This is the default profiler level
1 : The profiler collects data for the operations that take longer than the value of slowms.
By default any operations that take longer than 100ms is considered slow by mongod.
2 : The profiler collects data for all operations.
This profiler setting is considered dangerous, since it will log all operations that can generate huge amounts of write to the system.profile collection and put a load on the system.
To get the status about profilinglevel on the active database use the following command :
db.getProfilingLevel()
db.getProfilingLevel()
To change the value of the profilinglevel on the active database use the following command :
db.setProfilingLevel(1)
db.setProfilingLevel(1)
To set the slowms value use the following command :
db.setProfilingLevel(1, { slowms: 0 })
db.setProfilingLevel(1, { slowms: 0 })
To get the data collected in the system.profile collection use the following command :
LDAP is a way of organizing and storing information about people, groups, and computers in a central place. Think of it as a digital address book that can be accessed from anywhere on a network.
KERBEROS :
Kerberos is a network authentication protocol. It is designed to provide strong authentication for client/server applications by using secret-key cryptography
Authorization
Role based access control :
Each user has one or more roles
Each role has one or more privileges
A privilege represents a group of Actions and Resources those actions apply to.
Basic Security : Part 2
Localhost Exception
Allows you to access Mongodb server that has authenticationenabled but does not yet have a configureduser for you to authenticate with.
Must run mongo shell from the samehost running the mongodb server
The localhostexception closes after the firstuser is created.
Always the first user created should have administrative privileges.
Create a administrative user
The administrative user can be created with the localhost exception
To create the administrativeuser use the following command in the mongo shell :
There are many tools that come along when we install mongodb
The list of the tools that we need are :
mongostat :
The output of the mongostat command lists the following details :
Insert, query, update, delete, getmore, command
These fields represent the no. of operations occuring per second
dirty :
percentage of dirty bytes in the cache
used :
percentage of bytes used in the cache
vsize :
amount of virtual memory used by the process
res :
amount of resident memory used by the process
net_in :
amount of network traffic that is recieved
net_out :
amount of network traffic that is sent
mongoimport :
This is the inverse of the mongoexport command
Since we do not provide a database and collection name while using this command it defaults to test as the database and name of the collections is picked up from the name of the file.
mongoexport :
This command deals with outputting the information or the collections present in the mongodb in json format instead of bson
When the command is used with several arguments such as username and password it creates a dumpdirectory which contains the directory named by the collection you dumped.
The directory contains a .bson file which contains the actual information and metadata.json file which contains the information about the indexes in the collections