MongoDB database storage

Source: Internet
Author: User
Tags findone mongodb server mongo shell

Each MongoDB server supports multiple databases. Each database is relatively independent. For security purposes and convenience of management, the database data is also stored independently.

Mongo metadata

In the MongoDB database, the namespace <dbname>. system. * is a special collection containing multiple types of system information, as follows:

  • System. namespacesLists All namespaces.
  • System. IndexesList all indexes.
  • The metadata of the attached namespace and index is stored in database. ns in the form of confusion.
  • System. ProfileContains the profile information of the database.
  • System. UsersList all users that can access the database.
  • Local. SourcesContains the server information and status of the replication peer (slave.
  • The structure information of the object is stored in the object. For more information, see bson.

The following restrictions apply to modifying objects in a system set. Insert data in {system. Indexes} to create an index. However, the table information is immutable (the special drop Index Command will automatically update the relevant information ). {System. Users} can be modified. {System. Profile} can be deleted.

Note:$Is a reserved character. Do not use it in the namespace or field name. The internal index-related set will be used in the name$Character. These sets are saved as B-tree sets (cannot be directly queried ).

Database commands
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
  • [Database command list]

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 command

Some 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 information

Use 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 .)

A database can contain one or more sets, and each set can store document objects. You can also set an optional security authentication for these operations.

  • Mongo metadata
  • Database commands

    • Clone Database
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.