{"id":1675,"date":"2018-03-11T17:06:34","date_gmt":"2018-03-11T22:06:34","guid":{"rendered":"http:\/\/bluegalaxy.info\/codewalk\/?p=1675"},"modified":"2019-12-04T09:19:11","modified_gmt":"2019-12-04T14:19:11","slug":"mongodb-get-running-less-5-minutes","status":"publish","type":"post","link":"https:\/\/bluegalaxy.info\/codewalk\/2018\/03\/11\/mongodb-get-running-less-5-minutes\/","title":{"rendered":"MongoDB: How to get up and running in less than 5 minutes (on Windows)"},"content":{"rendered":"<p>MongoDB is a &#8220;NoSQL&#8221; (non-relational) data store of documents that have no predefined schema, where data is stored as a series of JSON objects. The concept of the relational database where there is a database that has tables which are made up of columns and rows, is replaced by the MongoDB concept of a database consisting of &#8220;collections&#8221;, which are made up of documents full of JSON objects.<\/p>\n<p>This article will focus mainly on the installation of MongoDB on Windows in order to get up and running with it quickly.<\/p>\n<h4><strong>Step 1: Download and run the .msi<\/strong><\/h4>\n<p>The .msi can be downloaded from here:<br \/>\n<a href=\"https:\/\/www.mongodb.com\/download-center?jmp=nav#community\">https:\/\/www.mongodb.com\/download-center?jmp=nav#community<\/a><\/p>\n<p>Choose the Community Server option:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1676\" src=\"http:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/03\/mdb_install.jpg\" alt=\"\" width=\"655\" height=\"347\" srcset=\"https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/03\/mdb_install.jpg 1079w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/03\/mdb_install-300x159.jpg 300w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/03\/mdb_install-768x406.jpg 768w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/03\/mdb_install-1024x542.jpg 1024w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/03\/mdb_install-676x358.jpg 676w\" sizes=\"auto, (max-width: 655px) 100vw, 655px\" \/><\/p>\n<p>The name of the file to download is:<br \/>\nmongodb-win32-x86_64-2008plus-ssl-3.6.3-signed.msi<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1677\" src=\"http:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/03\/mdb_install2.jpg\" alt=\"\" width=\"430\" height=\"200\" srcset=\"https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/03\/mdb_install2.jpg 430w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/03\/mdb_install2-300x140.jpg 300w\" sizes=\"auto, (max-width: 430px) 100vw, 430px\" \/><\/p>\n<p>While the installation is running, one of the screens will give the option to choose Complete or Custom. Choose Custom.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1678\" src=\"http:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/03\/mdb_install3.jpg\" alt=\"\" width=\"492\" height=\"384\" srcset=\"https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/03\/mdb_install3.jpg 492w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/03\/mdb_install3-300x234.jpg 300w\" sizes=\"auto, (max-width: 492px) 100vw, 492px\" \/><\/p>\n<p>Then choose Browse:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1681\" src=\"http:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/03\/mdb_install4.jpg\" alt=\"\" width=\"491\" height=\"381\" srcset=\"https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/03\/mdb_install4.jpg 491w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/03\/mdb_install4-300x233.jpg 300w\" sizes=\"auto, (max-width: 491px) 100vw, 491px\" \/><\/p>\n<p>This is to change the default installation location from what they recommend:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"no-highlight\">C:\\Program Files\\MongoDB\\Server\\3.6\\<\/code><\/p>\n<p>to<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"no-highlight\">C:\\mongodb<\/code><\/p>\n<p>Then click Next to continue on with the installation. I chose to allow the installation of MongoDB Compass also.<\/p>\n<p>&nbsp;<\/p>\n<h4><strong>Step 2: Create folders and run commands in the cmd line<br \/>\n<\/strong><\/h4>\n<p>In the new C:\\mongodb folder, add a data folder and a log folder.<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"no-highlight\">C:\\mongodb\\data<\/code><br \/>\n<code class=\"EnlighterJSRAW\" data-enlighter-language=\"no-highlight\">C:\\mongodb\\log<\/code><\/p>\n<p>In the data folder, add a db folder:<br \/>\n<code class=\"EnlighterJSRAW\" data-enlighter-language=\"no-highlight\">C:\\mongodb\\data\\db<\/code><\/p>\n<p>Now open a command prompt in Administrator mode. cd to the mongodb\\bin folder.<br \/>\n<code class=\"EnlighterJSRAW\" data-enlighter-language=\"no-highlight\">C:\\mongodb\\bin<\/code><\/p>\n<p>Then type this command:<br \/>\n<code class=\"EnlighterJSRAW\" data-enlighter-language=\"no-highlight\">mongod --directoryperdb --dbpath C:\\mongodb\\data\\db --logpath C:\\mongodb\\log\\mongo.log --logappend \u2013install<\/code><\/p>\n<p>Then run this command:<br \/>\n<code class=\"EnlighterJSRAW\" data-enlighter-language=\"no-highlight\">net start MongoDB<\/code><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1688\" src=\"http:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/03\/mongo_cmd1.png\" alt=\"\" width=\"366\" height=\"53\" srcset=\"https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/03\/mongo_cmd1.png 366w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/03\/mongo_cmd1-300x43.png 300w\" sizes=\"auto, (max-width: 366px) 100vw, 366px\" \/><\/p>\n<p>Then run this command, while still in the bin directory:<br \/>\n<code class=\"EnlighterJSRAW\" data-enlighter-language=\"no-highlight\">mongo<\/code><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1689\" src=\"http:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/03\/mongo_cmd2.png\" alt=\"\" width=\"340\" height=\"98\" srcset=\"https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/03\/mongo_cmd2.png 340w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/03\/mongo_cmd2-300x86.png 300w\" sizes=\"auto, (max-width: 340px) 100vw, 340px\" \/><\/p>\n<p>Note: There may also be some warning messages in addition to what is shown in the screen shot above.<\/p>\n<p>Type <code class=\"EnlighterJSRAW\" data-enlighter-language=\"no-highlight\">cls<\/code> to clear the screen. Then run these commands:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"no-highlight\">show dbs<\/code><\/p>\n<p>followed by &#8216;use&#8217; and then the name of the database you want to create. In this case I want to create a db called \u2018microblogs\u2019.<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"no-highlight\">use microblogs<\/code><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1690\" src=\"http:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/03\/mongo_cmd3.png\" alt=\"\" width=\"208\" height=\"97\"><\/p>\n<p>The command <code class=\"EnlighterJSRAW\" data-enlighter-language=\"no-highlight\">db<\/code> will show you which database you are currently in.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1691\" src=\"http:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/03\/mongo_cmd4.png\" alt=\"\" width=\"95\" height=\"47\"><\/p>\n<p>&nbsp;<\/p>\n<h4><strong>Step 3: Create user<\/strong><\/h4>\n<p>For more information about creating a user, see:<br \/>\n<a href=\"https:\/\/docs.mongodb.com\/manual\/reference\/method\/db.createUser\/\">https:\/\/docs.mongodb.com\/manual\/reference\/method\/db.createUser\/<\/a><\/p>\n<p>Run the following command block to create new user:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"no-highlight\">db.createUser({\n\tuser: \"chris\",\n\tpwd: \"password\",\n\troles: [ \"readWrite\", \"dbAdmin\" ]\n});\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1692\" src=\"http:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/03\/mongo_cmd5.png\" alt=\"\" width=\"675\" height=\"116\" srcset=\"https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/03\/mongo_cmd5.png 675w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/03\/mongo_cmd5-300x52.png 300w\" sizes=\"auto, (max-width: 675px) 100vw, 675px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h4><strong>Step 4: Create a collection<br \/>\n<\/strong><\/h4>\n<p>Run the following commands:<br \/>\n<code class=\"EnlighterJSRAW\" data-enlighter-language=\"no-highlight\">db.createCollection('blogs');<\/code><\/p>\n<p>then<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"no-highlight\">show collections<\/code><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1693\" src=\"http:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/03\/mongo_cmd6.png\" alt=\"\" width=\"259\" height=\"81\"><\/p>\n<p>For more information about setting up MongoDB, you can follow along with the Traversy Media video here:<\/p>\n<p><iframe loading=\"lazy\" title=\"MongoDB In 30 Minutes\" width=\"676\" height=\"380\" src=\"https:\/\/www.youtube.com\/embed\/pWbMrx5rVBE?start=321&#038;feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>MongoDB is a &#8220;NoSQL&#8221; (non-relational) data store of documents that have no predefined schema, where data is stored as a series of JSON objects. The concept of the relational database where there is a database that has tables which are made up of columns and rows, is replaced by the MongoDB concept of a database &hellip; <a href=\"https:\/\/bluegalaxy.info\/codewalk\/2018\/03\/11\/mongodb-get-running-less-5-minutes\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">MongoDB: How to get up and running in less than 5 minutes (on Windows)<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[78],"tags":[62,115],"class_list":["post-1675","post","type-post","status-publish","format-standard","hentry","category-technologies-and-tools","tag-json","tag-mongodb"],"_links":{"self":[{"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/posts\/1675","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/comments?post=1675"}],"version-history":[{"count":17,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/posts\/1675\/revisions"}],"predecessor-version":[{"id":2980,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/posts\/1675\/revisions\/2980"}],"wp:attachment":[{"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/media?parent=1675"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/categories?post=1675"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/tags?post=1675"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}