Mongodb Guide (translation) (9)-developer zone-database commands (4)

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

Verification command

Use this command to check whether a set is valid (no error) and obtain a lot of statistics.

This command scans the entire set and its indexes, and is slow on large datasets.

Operate from mongo shell:

> db.foo.validate()
{"ns" : "test.foo" , "result" : "
validate
details: 08D03C9C ofs:963c9c
firstExtent:0:156800 ns:test.foo
lastExtent:0:156800 ns:test.foo
# extents:1
datasize?:144 nrecords?:3 lastExtentSize:2816
padding:1
first extent:
loc:0:156800 xnext:null xprev:null
ns:test.foo
size:2816 firstRecord:0:1568b0 lastRecord:0:156930
3 objects found, nobj:3
192 bytes data w/headers
144 bytes data wout/headers
deletedList: 0000000100000000000
deleted: n: 1 size: 2448
nIndexes:1
test.foo.$x_1 keys:3
" , "ok" : 1 , "valid" : true , "lastExtentSize" : 2816}

From a driver, you can call a driver function like this:

> db.$cmd.findOne({validate:"foo" } );

Validate carries an optional scan data parameter, skipping the scanning of the basic set (but still scanning the index ).

> db.$cmd.findOne({validate:"foo", scandata:true});

This is a blocking operation (similar to repaireDatabase ).

Windows Services

On the Windows platform, mongodb.exe is installed and runs as a service with internal support.

Service commands

Service-related Commands include:

mongod --install
mongod --service
mongod --remove
mongod --reinstall

You can pass the following options to -- install and -- reinstall

--serviceName {arg}
--serviceUser {arg}
--servicePassword {arg}

The -- install and -- remove options install and remove the mongo daemon as windows Services respectively. -- Service option to start this service. -- Reinstall: try to remove the service and then install it. If the server is not installed, -- reinstall can still work normally.

If the service is running, -- remove and -- reinstall both stop the service.

Use -- serviceName to change the service name. To run mongo as a local or domain user relative to a local system account, use -- serviceUser and -- servicePassword.

It's not true that you have passed another command in mongod's command line, which will be configured for mongod.exe runtime. Use the following command line as an example (these parameters are not required for running mongod as a Service ):

mongod --logpath d:\mongo\logs --logappend --dbpath d:\mongo\data --directoryperdb --install

Run the following example to trigger the startup of a service named Mongo:

mongod --logpath d:\mongo\logs --logappend --dbpath d:\mongo\data --directoryperdb

Install Windows 7

If you install Windows 7, make sure that you are running as the administrator. To confirm this, open the Start menu and enter "cmd.exe" in the search box. When the execution page appears, right-click it and select "Run as administrator ".

In this step, you can install MongoDB as a service according to the usage -- install described above.

Mongos runs as a Windows Service

At this time (at least 1.8.x), mongos does not support direct installation as a service. However, with windows resource suite, you can configure a Windows host to start mongos as a system startup Item. (MongoDB 1.8.1 passed the Windows test)

  1. Assume that your mongos configuration file is in C: \ MongoDB \ mongos. conf and you have tested it to work.
  2. Use the administrator ID to start cmd.exe
  3. Install srvany.exe as a service, such as: C: \ Program Files \ Windows resource kits \ tools> "C: \ Program Files \ Windows Resource
    Kits \ Tools \ instsrv.exe "mongos" C: \ Program Files \ Windows Resource Kits \ Tools \ srvany.exe ", the output is similar:
    The service was successfuly added\!
    Make sure that you go into the Control Panel and use
    the Services applet to change the Account Name and
    Password that this newly installed service will use
    for its Security Context.
  4. Start regedit.exe
  5. Find the subkey
    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\mongos
  6. Right-click mongos and choose new> keyword. Name the keyword parameter.
  7. Select the parameter keyword.
  8. Right-click the window on the right and choose new> string value. Name the new application.
  9. The value of the modified application is the full path of ipvs.exe (for example, c: \ mongodb \ bin \ mongs.exe ).
  10. In the right window, right-click again. Choose new> string value to name the new application parameter.
  11. Modify the application parameters to mongos parameters (for example, -- config c: \ mongodb \ mongos. conf ).
  12. Use "net start mongos" to check whether the service can be started.
Mongo metadata

The <Database Name>. system. * namespace in MongoDB is special and contains the database system information. The system set includes:

  • System. namespaces: list all namespaces
  • System. indexes: list all indexes
  • The additional namespace/index metadata is stored in the database. ns file and is not transparent.
  • System. profile stores database evaluation information.
  • System. users List users that can access the database
  • Local. sources stores the configuration data and status of the replication group from the node.
  • The structure of the stored object is careful.

There are some restrictions on processing objects in the system set. Inserting System. indexes will add an index, but this table cannot be changed (a special drop index command can help you update it ). System. Users can be changed. System. profile can be discarded.

Note: $ is a reserved character. Do not use it in the namespace or internal field name. Indicates that the internal set of indexes uses $ in their names. These sets store B-tree block data and do not use the bson format (direct query is not allowed at this time ).

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.