MongoDB: db.runCommand() method
db.runCommand
The db.runCommand() method is used to provide a helper to run specified database commands.
Syntax:
db.runCommand(command)
Parameters:
Name | Description | Required / Optional |
Type |
---|---|---|---|
command | "A database command, specified either in document form or as a string. If specified as a string, db.runCommand() transforms the string into a document." | Required | document or string |
Example: MongoDB: db.runCommand() method
The following command will display the helper to run $gt command.
db.runCommand('$gt()');
Output:
> db.runCommand('$gt()'); { "ok" : 0, "errmsg" : "no such cmd: $gt()", "code" : 59, "bad cmd" : { "$gt()" : 1 } }
Retrieve the restaurants data from here
Behavior
db.runCommand() runs the command in the context of the current database. Some commands are only applicable in the context of the admin database, and you must change your db object to before running these commands.
Previous:
db.repairDatabase() method
Next:
db.serverBuildInfo() method
- Weekly Trends
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
- JavaScript functions Exercises
- Python Tutorial
- Python Array Exercises
- SQL Cross Join
- C# Sharp Array Exercises
We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook