MongoDB Database commands
The MongoDB database commands are used to create, modify, and update the database.
The admin command method runs against the admin database to run specified database commands by providing a helper.
Command: Either the argument is specified in the document form or a string form. If the command is defined as a string, it cannot include any argument.
Creating a user named JavaTpoint with the dbOwner role on the admin database.
The aggregate method initialize a specific diagnostic or admin pipeline, which does not require anu underlying collection.
The pipeline parameter does not require any underlying collection and always starts with a compatible stage, such as $currentOp or $listLocalSessions. It is an array of stages that will be executed.
The following example runs a pipeline with two stages. The first is the $currentOp operation and the second will filters the results.
The clonedatabase method copies the specified database to the current database and assumes that the database at the remote location has the same name as the current database.
The hostname parameter contains the hostname of the database that we want to copy.
We have the help option for the specified database command using the commandHelp method. The command parameter contains the name of a database command.
#5. db.createCollection(name, options)
A new collection or view will be created using this method. The createCollection method is used primarily for creating new collections that use specific options when the collection is first referenced in a command.
When we applying the specified aggregation pipeline to the collection, the createView method create a new view for the collection. The method can be computed during the read operations and acts as read-only operations. The views can be created in the same database of the source collection to executes read operations as a part of the underlying aggregation pipeline.
The following example creates a StudentFeedback view with the _id, student.management, and department fields:
The drop method removes the specified database and the associated data files.
For example -
we use <database> operation to switch the current database to the temporary database. We use the db.dropDatabase() method to drops the temporary database
The getLog method returns the current stiltedly settings. The method determines the amount of Log Messages produced by MongoDB for each log message component.