{"id":261,"date":"2017-05-15T06:57:16","date_gmt":"2017-05-15T13:57:16","guid":{"rendered":"http:\/\/www.kenwalger.com\/blog\/?p=261"},"modified":"2017-05-10T21:31:47","modified_gmt":"2017-05-11T04:31:47","slug":"mongodb-cli-tools","status":"publish","type":"post","link":"https:\/\/www.kenwalger.com\/blog\/nosql\/mongodb-cli-tools\/","title":{"rendered":"MongoDB CLI Tools"},"content":{"rendered":"<p>I have discussed one of the GUI tools <a href=\"http:\/\/www.mongodb.com\">MongoDB<\/a> offers, <a href=\"http:\/\/www.kenwalger.com\/blog\/nosql\/mongodb\/mongodb-compass-an-overview\/\">Compass<\/a>, previously. Sometimes, however, using the command line interface (CLI) is required. MongoDB provides some very helpful CLI tools. Let&#8217;s have a quick look at what is included in the MongoDB installation package, and what the tools and files do.<\/p>\n<h3>Package Components<\/h3>\n<p>There are two main types of files which come included in the MongoDB <a href=\"https:\/\/www.mongodb.com\/download-center\">download<\/a>, process\/service files and tools. The process files are the core components of the MongoDB system include the following:<\/p>\n<h6>Process<\/h6>\n<ul>\n<li><a href=\"https:\/\/docs.mongodb.com\/manual\/reference\/program\/mongod\/\">mongod<\/a>, which is the core database process<\/li>\n<li><a href=\"https:\/\/docs.mongodb.com\/manual\/reference\/program\/mongos\/\">mongos<\/a>, which controls and routes queries in a sharded environment<\/li>\n<li><a href=\"https:\/\/docs.mongodb.com\/manual\/reference\/program\/mongo\/\">mongo<\/a> is the interactive, JavaScript based, MongoDB shell.<\/li>\n<\/ul>\n<h6>Service<\/h6>\n<p>In the Windows download there are some additional files for running and configuring MongoDB as a Windows Service.<\/p>\n<ul>\n<li><a href=\"https:\/\/docs.mongodb.com\/manual\/reference\/program\/mongod.exe\/\">mongod.exe<\/a>, the core database<\/li>\n<li><a href=\"https:\/\/docs.mongodb.com\/manual\/reference\/program\/mongos.exe\/\">mongos.exe<\/a>, the sharded environment controller<\/li>\n<\/ul>\n<p>These are the main applications you will find yourself using most often to get the server up and running (<code>mongod<\/code>) and interacting with the server in the mongo shell (<code>mongo<\/code>). It is possible to get\u00a0<em>some<\/em> server information with shell database methods such as <a href=\"https:\/\/docs.mongodb.com\/manual\/reference\/method\/db.serverStatus\/#db.serverStatus\">serverStatus()<\/a> and <a href=\"https:\/\/docs.mongodb.com\/manual\/reference\/method\/db.stats\/#db.stats\">stats().<\/a>\u00a0However, there are some CLI tools which offer much more detailed information for us.<\/p>\n<h4>CLI Tools<\/h4>\n<p>There are a couple of different buckets in which the CLI tools fall;\u00a0import\/export and diagnostic tools. Let&#8217;s take a closer look:<\/p>\n<h6>Import\/Export Tools<\/h6>\n<p>As with most databases, having a way to bring data into and out of the database is extremely useful. MongoDB is no different. Being a document database doesn&#8217;t mean that it can&#8217;t provide a way to utilize structured data when needed. Or, to provide a way to export it&#8217;s rich document data for use elsewhere.<\/p>\n<p>MongoDB stores data on disk in <a href=\"https:\/\/docs.mongodb.com\/manual\/reference\/glossary\/#term-bson\">BSON <\/a>format and allows for the importing (restoration) and exporting (dumping) of files in this format with the following CLI tools.<\/p>\n<ul>\n<li><a href=\"https:\/\/docs.mongodb.com\/manual\/reference\/program\/mongodump\/\">mongodump<\/a>, generates a BSON file from a running mongod server.<\/li>\n<li><a href=\"https:\/\/docs.mongodb.com\/manual\/reference\/program\/mongorestore\/\">mongorestore<\/a> allows for the restoration of the files<\/li>\n<\/ul>\n<p>There also in an included application, <a href=\"https:\/\/docs.mongodb.com\/manual\/reference\/program\/bsondump\/\">bsondump<\/a>, which will convert the BSON dump files into JSON files. Recall that BSON is a binary form of JSON and includes some important data features such as data typing, such as date, integer, long, double, and decimal.<\/p>\n<p>For working with formats\u00a0<em>other than<\/em> BSON, MongoDB provides for support for importing\u00a0<strong>and<\/strong> exporting data in JSON, CSV, or TSV format.\u00a0These can be especially useful when bringing in established relational data of many types.<\/p>\n<ul>\n<li><a href=\"https:\/\/docs.mongodb.com\/manual\/reference\/program\/mongoimport\/\">mongoimport<\/a> brings the JSON, CSV, or TSV formatted data into a running MongoDB database<\/li>\n<li><a href=\"https:\/\/docs.mongodb.com\/manual\/reference\/program\/mongoexport\/\">mongoexport<\/a>, yep you guessed it,\u00a0<em>exports<\/em> the database data.<\/li>\n<\/ul>\n<h6>CLI Tools for Diagnosis<\/h6>\n<p>This is where the real workhorses come in for examining the health of your MongoDB server environment. The provided tools allow for the examination of the current operation of a MongoDB server. One can also look at, and capture, network traffic or manage LDAP configurations.<\/p>\n<ul>\n<li><a href=\"https:\/\/docs.mongodb.com\/manual\/reference\/program\/mongostat\/\">mongostat<\/a> is great for a obtaining the overview status of a running mongod or mongos instance. For example, it can provide information regarding the number of inserts, queries, updates, or deletes and lots more.\n<p><figure id=\"attachment_265\" aria-describedby=\"caption-attachment-265\" style=\"width: 300px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/05\/mongostat-e1494453466422.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"265\" data-permalink=\"https:\/\/www.kenwalger.com\/blog\/nosql\/mongodb-cli-tools\/attachment\/mongostat\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/05\/mongostat-e1494453466422.png?fit=1037%2C539&amp;ssl=1\" data-orig-size=\"1037,539\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"mongostat\" data-image-description=\"\" data-image-caption=\"&lt;p&gt;Mongostat results while doing large inserts&lt;\/p&gt;\n\" data-medium-file=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/05\/mongostat-e1494453466422.png?fit=300%2C156&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/05\/mongostat-e1494453466422.png?fit=840%2C436&amp;ssl=1\" class=\"size-medium wp-image-265\" src=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/05\/mongostat-300x156.png?resize=300%2C156\" alt=\"Mongostats\" width=\"300\" height=\"156\" \/><\/a><figcaption id=\"caption-attachment-265\" class=\"wp-caption-text\">Mongostat results while doing large inserts<\/figcaption><\/figure><\/li>\n<li><a href=\"https:\/\/docs.mongodb.com\/manual\/reference\/program\/mongotop\/\">mongotop<\/a>\u00a0looks at, at a collection level, the time for reading and writing of data. It provides, at a high level, a view of where Mongodb is spending it&#8217;s time.\n<p><figure id=\"attachment_266\" aria-describedby=\"caption-attachment-266\" style=\"width: 300px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/05\/mongotop.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"266\" data-permalink=\"https:\/\/www.kenwalger.com\/blog\/nosql\/mongodb-cli-tools\/attachment\/mongotop\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/05\/mongotop.png?fit=1804%2C1078&amp;ssl=1\" data-orig-size=\"1804,1078\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"mongotop\" data-image-description=\"\" data-image-caption=\"&lt;p&gt;mongotop results while doing inserts&lt;\/p&gt;\n\" data-medium-file=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/05\/mongotop.png?fit=300%2C179&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/05\/mongotop.png?fit=840%2C502&amp;ssl=1\" class=\"size-medium wp-image-266\" src=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/05\/mongotop-300x179.png?resize=300%2C179\" alt=\"mongotop\" width=\"300\" height=\"179\" srcset=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/05\/mongotop.png?resize=300%2C179&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/05\/mongotop.png?resize=768%2C459&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/05\/mongotop.png?resize=1024%2C612&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/05\/mongotop.png?resize=1200%2C717&amp;ssl=1 1200w, https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/05\/mongotop.png?w=1804&amp;ssl=1 1804w, https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/05\/mongotop.png?w=1680&amp;ssl=1 1680w\" sizes=\"auto, (max-width: 300px) 85vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-266\" class=\"wp-caption-text\">mongotop results while doing inserts<\/figcaption><\/figure><\/li>\n<li><a href=\"https:\/\/docs.mongodb.com\/manual\/reference\/program\/mongoperf\/\">mongoperf<\/a> checks disk performance<\/li>\n<li><a href=\"https:\/\/docs.mongodb.com\/manual\/reference\/program\/mongoreplay\/\">mongoreplay<\/a> is pretty cool. It allows for, among other things, the capture of commands sent to a MongoDB instance and the ability to replay them in a different environment. This is very handy for testing and trouble shooting.<\/li>\n<li><a href=\"https:\/\/docs.mongodb.com\/manual\/reference\/program\/mongoldap\/\">mongoldap<\/a> allows for testing LDAP configuration options against LDAP server(s).<\/li>\n<\/ul>\n<h6>Other Tools<\/h6>\n<p>The last tool which comes in the MongoDB package is <a href=\"https:\/\/docs.mongodb.com\/manual\/reference\/program\/mongofiles\/\">mongofiles<\/a> which allows for interaction with <a href=\"https:\/\/docs.mongodb.com\/manual\/core\/gridfs\/\">GridFS<\/a> objects. GridFS allows for the storage of files larger than the BSON limit of 16MB per document.<\/p>\n<h3>Conclusion<\/h3>\n<p>Graphical User Interfaces (GUI) are great, but sometimes you will find it necessary to use a CLI tool to really understand what is going on with your system. MongoDB provides a great assortment of tools to do just that. I would recommend having a look at some of them to expand your personal tool-kit.<\/p>\n<hr \/>\n<p><em>Follow me on Twitter <a href=\"https:\/\/www.twitter.com\/kenwalger\">@kenwalger<\/a> to get the latest updates on my postings.<\/em><\/p>\n<a class=\"synved-social-button synved-social-button-share synved-social-size-48 synved-social-resolution-single synved-social-provider-facebook nolightbox\" data-provider=\"facebook\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Facebook\" href=\"https:\/\/www.facebook.com\/sharer.php?u=https%3A%2F%2Fwww.kenwalger.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F261&#038;t=MongoDB%20CLI%20Tools&#038;s=100&#038;p&#091;url&#093;=https%3A%2F%2Fwww.kenwalger.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F261&#038;p&#091;images&#093;&#091;0&#093;=https%3A%2F%2Fi0.wp.com%2Fwww.kenwalger.com%2Fblog%2Fwp-content%2Fuploads%2F2017%2F05%2Fcli-e1494469690651.png%3Ffit%3D125%252C125%26ssl%3D1&#038;p&#091;title&#093;=MongoDB%20CLI%20Tools\" style=\"font-size: 0px;width:48px;height:48px;margin:0;margin-bottom:5px;margin-right:5px\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" alt=\"Facebook\" title=\"Share on Facebook\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"48\" height=\"48\" style=\"display: inline;width:48px;height:48px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/96x96\/facebook.png?resize=48%2C48&#038;ssl=1\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-48 synved-social-resolution-single synved-social-provider-twitter nolightbox\" data-provider=\"twitter\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Twitter\" href=\"https:\/\/twitter.com\/intent\/tweet?url=https%3A%2F%2Fwww.kenwalger.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F261&#038;text=Hey%20check%20this%20out\" style=\"font-size: 0px;width:48px;height:48px;margin:0;margin-bottom:5px;margin-right:5px\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" alt=\"twitter\" title=\"Share on Twitter\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"48\" height=\"48\" style=\"display: inline;width:48px;height:48px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/96x96\/twitter.png?resize=48%2C48&#038;ssl=1\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-48 synved-social-resolution-single synved-social-provider-reddit nolightbox\" data-provider=\"reddit\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Reddit\" href=\"https:\/\/www.reddit.com\/submit?url=https%3A%2F%2Fwww.kenwalger.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F261&#038;title=MongoDB%20CLI%20Tools\" style=\"font-size: 0px;width:48px;height:48px;margin:0;margin-bottom:5px;margin-right:5px\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" alt=\"reddit\" title=\"Share on Reddit\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"48\" height=\"48\" style=\"display: inline;width:48px;height:48px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/96x96\/reddit.png?resize=48%2C48&#038;ssl=1\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-48 synved-social-resolution-single synved-social-provider-linkedin nolightbox\" data-provider=\"linkedin\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Linkedin\" href=\"https:\/\/www.linkedin.com\/shareArticle?mini=true&#038;url=https%3A%2F%2Fwww.kenwalger.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F261&#038;title=MongoDB%20CLI%20Tools\" style=\"font-size: 0px;width:48px;height:48px;margin:0;margin-bottom:5px;margin-right:5px\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" alt=\"linkedin\" title=\"Share on Linkedin\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"48\" height=\"48\" style=\"display: inline;width:48px;height:48px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/96x96\/linkedin.png?resize=48%2C48&#038;ssl=1\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-48 synved-social-resolution-single synved-social-provider-mail nolightbox\" data-provider=\"mail\" rel=\"nofollow\" title=\"Share by email\" href=\"mailto:?subject=MongoDB%20CLI%20Tools&#038;body=Hey%20check%20this%20out:%20https%3A%2F%2Fwww.kenwalger.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F261\" style=\"font-size: 0px;width:48px;height:48px;margin:0;margin-bottom:5px\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" alt=\"mail\" title=\"Share by email\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"48\" height=\"48\" style=\"display: inline;width:48px;height:48px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/96x96\/mail.png?resize=48%2C48&#038;ssl=1\" \/><\/a>","protected":false},"excerpt":{"rendered":"<p>I have discussed one of the GUI tools MongoDB offers, Compass, previously. Sometimes, however, using the command line interface (CLI) is required. MongoDB provides some very helpful CLI tools. Let&#8217;s have a quick look at what is included in the MongoDB installation package, and what the tools and files do. Package Components There are two &hellip; <a href=\"https:\/\/www.kenwalger.com\/blog\/nosql\/mongodb-cli-tools\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;MongoDB CLI Tools&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":268,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"pmpro_default_level":"","_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4,3],"tags":[45],"yst_prominent_words":[268,1106,1105,258,266,263,99,104,972,260,264,259,87,262,193,270,261,102,265,1104],"class_list":["post-261","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mongodb","category-nosql","tag-cli-tools","pmpro-has-access"],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/05\/cli-e1494469690651.png?fit=125%2C125&ssl=1","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8lx70-4d","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/www.kenwalger.com\/blog\/wp-json\/wp\/v2\/posts\/261","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kenwalger.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kenwalger.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kenwalger.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kenwalger.com\/blog\/wp-json\/wp\/v2\/comments?post=261"}],"version-history":[{"count":4,"href":"https:\/\/www.kenwalger.com\/blog\/wp-json\/wp\/v2\/posts\/261\/revisions"}],"predecessor-version":[{"id":267,"href":"https:\/\/www.kenwalger.com\/blog\/wp-json\/wp\/v2\/posts\/261\/revisions\/267"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.kenwalger.com\/blog\/wp-json\/wp\/v2\/media\/268"}],"wp:attachment":[{"href":"https:\/\/www.kenwalger.com\/blog\/wp-json\/wp\/v2\/media?parent=261"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kenwalger.com\/blog\/wp-json\/wp\/v2\/categories?post=261"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kenwalger.com\/blog\/wp-json\/wp\/v2\/tags?post=261"},{"taxonomy":"yst_prominent_words","embeddable":true,"href":"https:\/\/www.kenwalger.com\/blog\/wp-json\/wp\/v2\/yst_prominent_words?post=261"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}