MongoDB finishing notes specify commands and specified files

Source: Internet
Author: User

The MongoDB shell is more than just an interactive shell, it also supports execution of specified JavaScript files, and also supports execution of specified command fragments. With this feature, MongoDB can be combined with the Linux shell to do most of the daily management and maintenance work.

executes the specified command

For example, there are several common ways to query the number of records in the T1 table of the test library, as follows:

[Email protected] bin]#/1.8.1connecting to:test> db.t1.count ()7>

Execute the statement directly from the command line eval parameter:

[Email protected] bin]#/mongo test--eval "Printjson (Db.t1.count ())"1.8.1connecting to:test7

execute the specified file

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

T1_count.js is the file we are going to execute, the contents are as follows

= Db.t1.count ();p Rintjson (' total count of T1 is: ' + totalcount ';p rintjson ('-----------------------') );

Below we will execute this file

[Email protected] bin]#./1.8.1connecting to:test"Total count of T1 is:7" "-----------------------"

You can see that finally get the T1 table record number 7, then some unnecessary descriptive text we do not want to appear, how to deal with it?

[[email protected] bin]#./mongo--quiet t1_count.js"total count of T1 is:7" "-----------------------"[[EMA Il protected] bin]#

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

MongoDB finishing notes specify commands and specified files

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.