| Introduction Mongo databases have database commands (DATABASE Command. These commands allow the database to perform certain operations or return some information about the current status of the database.
- Introduction
- Privileged command
- Get Command help information
- More instructions
A command will be used$ CmdA special query statement of the set is sent to the database. After the database is executed, a single document object will be returned as the result of the command. You can useFindone (). The basic command format is: db.$cmd.findOne( { <commandname>: <value> [, options] } ); In the command line environment, you can execute: db.runCommand( { <commandname>: <value> [, options] } ); For example, to check the profile level settings of the current database, run: > db.runCommand({profile:-1}); { "was" : 0.0 , "ok" : 1.0 } Most database drivers provide methods to encapsulate database commands for ease of use. For example, Mongo shell provides > db.getProfilingLevel() 0.0 The implementation of this method is as follows: > print( db.getProfilingLevel ) function () { var res = this._dbCommand({profile:-1}); return res ? res.was : null; } > print( db._dbCommand ) function (cmdObj) { return this.$cmd.findOne(cmdObj); } Most commands have similar simple usage-see the relevant documents of various database drivers. Privileged commandSome special operations can only be performed by administrators. These special operations will be performed in the {admin} database. > use admin; > db.runCommand("shutdown"); // shut down the database If the current database is not 'admin', you can use the _ admincommand method to perform the operation: > db._adminCommand("shutdown"); (For this operation, it is also easy to use dB. shutdownserver .) Get Command help informationUse the commandhelp command to obtain information about a command: > db.commandHelp("datasize") help for: datasize example: { datasize:"blog.posts", keyPattern:{x:1}, min:{x:10}, max:{x:55} } NOTE: This command may take awhile to run (Some commands do not have complete help information .) |