Advance Database and Shell command

In previous section we have discussed some example related to MongoDB with Java. In this section, we will understand some more Advance Database and Shell command

Advance Database command

CommandDescriptions
db.addUser()Adds a user to a Database and allows administrators to configure the user’s privileges
db.addauth()Authenticates a user to a database
db.changeUserPassword()Changes an existing user’s password
db.cloneCollection()Copies data directly between MongoDB instances. Wraps cloneCollection.
db.cloneDatabase()Copies a database from a remote host to the current host. Wraps clone.
db.commandHelp()Returns help information for a database command.
db.createCollection()Creates a new collection. Commonly used to create a capped collection.
db.currentOp()Reports the current-in-progress operations.
db.dropDatabase()Removes the current database.
db.eval()Passes a JavaScript function to the mongod instance for server-side JavaScript evaluation.
db.fsyncLock()Flushes writes to disk and locks the database to prevent write operations and assist backup operations. Wraps fsync.
db.getCollection()Returns a collection object. Used to access collections with names that are not valid in the Mongo Shell.
db.getCollectionNames()Lists all collections in the current database.
db.getLastError()Checks and returns the status of the last operation. Wraps getLastError.
db.getMongo()Returns the Mongo() connection object for the current connection.
db.getName()Returns the name of the current database.
db.getPrevError()Returns a status document containing all errors since last error reset. Wraps getPrevError.
db.getProfilingStatus()Returns a document that reflects the current profiling level and the profiling threshold.
db.getReplicationInfo()Returns a document with replication statistics.
db.getSiblingDB()Provides access to the specified database.
db.help()Displays descriptions of common db object methods.
db.hostInfo()Returns a document with information about the system MongoDB runs on. Wraps hostInfo.
db.isMaster()Returns a document that reports the state of the replica set.
db.killOp()Terminates a specified operation.
db.listCommands()Displays a list of common database commands.
db.loadServerScripts()Loads all scripts in the system.js for the current database into the shell session.
db.logout()Ends an authenticated session.
db.removeUser()Removes a user from a database.
db.repairDatabase()Runs a repair routine on the current database.
db.resetError()Reset the error message returned by db.getPrevError() and getPrevError.
db.runCommand()Runs a database command.
db.serverBuildInfo()Returns a document that displays the compilation parameters for the mongod instance. Wraps buildinfo.
db.serverStatus()Returns a document that provides an overview of the state of the database process.
db.setProfilingLevel()Modifies the current level of the database profiling.
db.shutdownServer()Shuts down the current mongod or mongos process cleanly and safely.
db.stats()Returns a document that reports on the state of  the current database.
db.version()Returns the version of the mongod instance.

Some Mongo Shell command

CommandDescription
db.collection.count()Wraps count to return a count of the number of    documents in a collection or matching a query.
db.collection.createIndex()Builds an index on a collection. Use db.collection.ensureIndex().
db.collection.getIndexStats()Renders a human-readable view of the data collected by indexStats which reflect B-tree utilization.
db.collection.dataSize()Returns the size of the collection. Wraps the size field in the output of the collStats.
db.collection.distinct()Returns an array of documents that have distinct values for the specified field.
db.collection.drop()Removes the specified collection from the database.
db.collection.dropIndex()Removes a specified index on a collection.
db.collection.dropIndexes()Removes all indexes on a collection.
db.collection.ensureIndex()Performs a query on a collection and returns a     cursor object.
db.collection.renameCollection()Changes the name of a collection.
db.collection.save()Provides a wrapper around an insert() and update() to insert new documents.
db.collection.stats()Reports on the state of a collection. Provides a wrapper around the collStats.
db.collection.storageSize()Reports the total size used by the collection. Provides a wrapper around the storageSize field of the collStats output.
db.collection.totalSize()Reports the total size of a collection, including the size of all documents and all indexes on a collection.
db.collection.totalIndexSize()Reports the total size used by the indexes on a collection. Provides a wrapper around the totalIndexSize field of the collStats output.
db.collection.update()Modifies a document in a collection.
db.collection.validate()Performs diagnostic operations on a collection.

In this tutorial we have understood some Advance Database and Shell command in MongoDB.

Leave a Reply

Your email address will not be published. Required fields are marked *