Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the MongoDB command line and process like

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article is to share with you about the MongoDB command line and process, the editor feels very practical, so share with you to learn, I hope you can learn something after reading this article, say no more, follow the editor to have a look.

Command line

MongoDB shell is not only an interactive shell, it also supports execution of specified javascript files as well as execution

The specified command fragment.

With this feature, you can perfectly combine MongoDB with linux shell to accomplish most of the day-to-day management and maintenance

Work.

1 execute the specified statement through the eval parameter

Usually we execute an order like this:

MongoDB shell version: 2.4.7connecting to: test > db.stu.count () 10 >

In fact, we can also do this: execute the statement directly through the command line eval parameter:

2 execute the contents of the specified file

If a lot of operations are involved before the result can be obtained, it is impossible to do it in the way of eval.

Then a more flexible way of executing specified files will come in handy. For example, we still need to check the notes in the stu table of the test library

Number of records:

Cat stu.jsvar total = db.stu.count (); printjson ('total count of stu is:'+ total); printjson (' -')

You can see that the final number of records in the stu table is 10, so if we don't want to write some unnecessary illustrative text

What should I do now?

By specifying the quiet parameter, you can mask some login information, which makes the result clearer.

II. Process control

DBA often has to solve some query performance problems of the system. At this time, the general operation habit is to check which processes are available first.

Then kill the abnormal process, so how does MongoDB handle it?

1 View active process

Look at the activity process so that you can understand what the system is doing so that you can judge the next step.

Db.currentOp () {"inprog": [{"opid": 62475494, "active": true, "secs_running": 2, "op": "getmore", "ns": "local.oplog.rs" "query": {} "client": "192.168.129.21 conn1938595", "desc": "conn1938595", "threadId": "0x40458940", "connectionId": 1938595, "waitingForLock": false, "numYields": 0 "lockStats": {"timeLockedMicros": {"r": NumberLong (83), "w": NumberLong (0)}, "timeAcquiringMicros": {"r": NumberLong (8) "w": NumberLong (0)]}

Field description:

Opid: operation process number

Op: operation type (query, update, etc.)

Ns: namespace, which refers to which object is being manipulated

Query: if the operation type is query, the specific query content will be displayed here.

LockType: type of lock, indicating whether it is a read lock or a write lock

2 end the process

If an exception is caused by a process, then DBA will usually kill the culprit mercilessly.

Process, the following will be the operation

> db.killOp (1234/*opid*/)

Note:

Do not use kill-initiated operations, such as replica set-initiated sync operations, etc.

The above is what the MongoDB command line and process are like, and the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report