Part III Management Chapter Nineth of the MongoDB shell eval, process

Source: Internet
Author: User
Tags eval install mongodb mongodb query

1. Execute the specified statement with the eval parameter

For example, the number of records in the T1 table that needs to query the test library is as follows:

[[email protected] bin]#./mongo test
MongoDB Shell version:2.6.6
Connecting To:test
> Db.t1.count ();
0
>

Execute the statement directly from the command line eval parameter:

[[email protected] bin]#./mongo test--eval "Printjson (Db.t1.count ())"
MongoDB Shell version:2.6.6
Connecting To:test
0


2. Execute the contents of the specified file

If it involves a lot of operations to get the results, then it is impossible to do it with Eval, so a more flexible way to execute the file is useful, for example we still want to see the number of records in the test Library T1 table:

T1_count.js is the file we want to specify, and the contents are as follows:
var totalcount=db.t1.count ();
Printjson (' Total count of T1 is: ' +totalcount);
Printjson ('--------------------');

Below we will execute this file:

[Email protected] bin]#/mongo t1_count.js
MongoDB Shell version:2.6.6
Connecting To:test
"Total count of T1 is:0"
"--------------------"

As you can see, the number of records in the final T1 table is 7, so what do we do if we don't want to see some unnecessary descriptive text?

[Email protected] bin]#/mongo --quiet t1_count.js
"Total count of T1 is:0"
"--------------------"
[Email protected] bin]#

By specifying the quiet parameter, you can mask some login information, which can make the results clearer.


3. Process Control

To solve the performance problems of the system, at this time the general operating habits are to see what processes, and then the exception of the process to kill, then MongoDB is how to deal with it?

View Active Processes

Review the active process to see what the system is doing to make the next decision:

>db.currentop ();

{inporg:[{"Opid": "OP": "Query", "ns": "Mydb.votes", "query": "{score:1.0}", "Inlock": 1}]

}

Field Description:

    • Opid: Operation Process Number
    • Op: Type of operation (query, update, etc.)
    • Ns: A namespace that refers to which object is manipulated
    • Query: If the operation type is a query, this will show the specific query content
    • LockType: The type of lock, indicating whether it is a read or write lock.
End ProcessIf an exception is due to a process, it will generally kill the process mercilessly, the following is the Operation>db.killop (1234/*opid*/)Note:do not kill internally initiated operations, such as sync operations initiated by replica set.

----------------------MongoDB Series Article update--------------------------------

The first part of the basic chapter into MongoDB

The first part of the basic chapter II install MongoDB

Part I basic chapter III MONGODB architecture

The first part of the basic chapter fourth MongoDB Quick Start

The first part of the basic chapter Fourth MongoDB query

Part Two application chapter Fifth MongoDB advanced query

Part Two application chapter sixth MongoDB Gridfs

Part Two application chapter seventh MongoDB MapReduce

Part III Management chapter eighth MONGODB service Management

Part III Management Chapter Nineth the MongoDB Shell system command, user command







Part III Management Chapter Nineth of the MongoDB shell eval, process

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.