MongoDB Learning notes-database commands

Source: Internet
Author: User
Tags mongodb server
Concept

A database command is a very special type of query. Document creation, updating, deletion, and querying are all part of the database command, and it also contains administrative tasks (such as shutting down the server and cloning the database), statistics, and performing aggregation operations.

RunCommand function

In general, it is possible to use only the functions provided by the shell, but it is helpful to know the commands underlying them. In particular, when using a version shell to connect to a new version of the database, the shell might not support some of the commands of the newer database, and then have to use the RunCommand function of the database command. How to use: Db.runcommand ({"Command name": value})

How Database commands work

The database command always returns a document that contains the "OK" key. If the value of "OK" is 1, the command execution succeeds. otherwise failed. If the "OK" value is 0, then the return document of the command will have an extra key-"errmsg". It is a string type used to describe the cause of the failure.

The above-mentioned "Database command" is a special type of query, because when the MongoDB server receives a command sent by a runcommand, it processes the request into a query operation of the $cmd collection. For example, Shel sends a db.runcommand ("Drop", "test") command (deleting a test collection) and the server is converted to DB. $cmd. FindOne ({"Drop": "Test"})

When some commands need to have administrator rights, and in the admin (MongoDB system comes from the database) database can be executed, you can not use the RunCommand function, instead of using the Admincommand function. Otherwise you will get an "Access Denied" error.

MongoDB Learning notes-database commands

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.