<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jack Keck</title>
    <description>The latest articles on DEV Community by Jack Keck (@jackkeck).</description>
    <link>https://dev.to/jackkeck</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F882%2F0a17f456-9e5e-40f3-8863-6804560aaa8a.jpeg</url>
      <title>DEV Community: Jack Keck</title>
      <link>https://dev.to/jackkeck</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jackkeck"/>
    <language>en</language>
    <item>
      <title>Setting up MongoDB Locally</title>
      <dc:creator>Jack Keck</dc:creator>
      <pubDate>Fri, 02 Aug 2019 18:51:48 +0000</pubDate>
      <link>https://dev.to/jackkeck/setting-up-mongodb-locally-1lm2</link>
      <guid>https://dev.to/jackkeck/setting-up-mongodb-locally-1lm2</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;A SIMPLE MONGO DATABASE&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;I've used MongoDB quite a bit and wanted to share how I usually approach building a quick instance locally. If you know me, you know that I enjoy when things are broken down Barney-style. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/GMalHy5bWkfN6/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/GMalHy5bWkfN6/giphy.gif" alt='gif of Barney the purple dinosaur singing "I love you, you love me..."' width="320" height="240"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So this should be easy to follow whether you're new to all this or a seasoned vet. With that said, we'll walk through:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Basic Installation&lt;/li&gt;
&lt;li&gt;Loading a Dataset&lt;/li&gt;
&lt;li&gt;Basic Security&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I relied on &lt;a href="https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/"&gt;MongoDB's installation instructions&lt;/a&gt; and their &lt;a href="https://docs.mongodb.com/"&gt;core documentation&lt;/a&gt; for the installation. Additional sources are noted inline as appropriate. If at any time you need to start over from scratch, you can use the Helpful Scraps section at the bottom. There are commands to clean up the database as well as how to perform a clean uninstall. Additionally, you can find the specifics of my local setup below.&lt;/p&gt;







&lt;h2&gt;
  
  
  &lt;strong&gt;MY LOCALHOST&lt;/strong&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;In the interest of transparency and sanity when debugging, these are the relevant details of my local environment.  &lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;strong&gt;Local Setup&lt;/strong&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;OS&lt;/strong&gt;: macOS Mojave 10.14.4&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;HOMEBREW&lt;/strong&gt;: Homebrew 2.1.9&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;GIT&lt;/strong&gt;: git version 2.22.0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;MONGODB&lt;/strong&gt;: MongoDB Community 4.0&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;







&lt;h2&gt;
  
  
  &lt;strong&gt;INSTALL&lt;/strong&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/ciwIbp8x2krQnhPgYu/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/ciwIbp8x2krQnhPgYu/giphy.gif" alt="gif of mongodb being installed in a terminal" width="480" height="333"&gt;&lt;/a&gt;&lt;br&gt;
Installing and starting MongoDB is simple. Open your terminal and use the below commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;brew tap mongodb/brew
brew &lt;span class="nb"&gt;install &lt;/span&gt;mongodb-community@4.0 
mongod &lt;span class="nt"&gt;--config&lt;/span&gt; /usr/local/etc/mongod.conf &amp;amp;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Homebrew's &lt;a href="https://docs.brew.sh/Taps"&gt;&lt;code&gt;tap&lt;/code&gt;&lt;/a&gt; command creates a shallow clone of &lt;a href="https://github.com/mongodb/homebrew-brew"&gt;MongoDB's formulae&lt;/a&gt;. This means that it adds a reference/link to that GitHub repository in your Homebrew for future use. &lt;/p&gt;

&lt;p&gt;We run &lt;a href="https://docs.brew.sh/Manpage#install-formula"&gt;&lt;code&gt;install&lt;/code&gt;&lt;/a&gt; knowing that it is using the MongoDB formulae we specified before. In addition to the MongoDB binaries, Homebrew creates your configuration file (&lt;code&gt;mongod.conf&lt;/code&gt;) and necessary paths.&lt;/p&gt;

&lt;p&gt;Despite using Homebrew for installation, we will not be using their &lt;a href="https://docs.brew.sh/Manpage#services-subcommand"&gt;&lt;code&gt;services&lt;/code&gt;&lt;/a&gt; command. This is because &lt;code&gt;brew services&lt;/code&gt; uses &lt;code&gt;launchctl&lt;/code&gt;'s plist files. Consequently, &lt;a href="https://github.com/Homebrew/homebrew-services/issues/186"&gt;it does not pull in a fresh copy of your configuration file on each startup.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Instead, we're directly invoking &lt;a href="https://docs.mongodb.com/manual/reference/program/mongod/"&gt;&lt;code&gt;mongod&lt;/code&gt;&lt;/a&gt;, MongoDB's parent process, with a reference to our 'mongod.conf' using the &lt;code&gt;--config&lt;/code&gt; flag. In Linux, the &lt;code&gt;&amp;amp;&lt;/code&gt; is a &lt;a href="https://www.w3resource.com/linux-system-administration/control-operators.php"&gt;control operator&lt;/a&gt;. It allows your shell to manage the command(s) issued in the background; this outputs the &lt;a href="http://www.linfo.org/pid.html"&gt;process identifier (PID)&lt;/a&gt;. If you want to verify, you can use &lt;code&gt;jobs -l&lt;/code&gt; to print the process running background and its PID. You can also use &lt;code&gt;ps&lt;/code&gt; (with a &lt;code&gt;| grep mongo*&lt;/code&gt; in this case). &lt;/p&gt;







&lt;h2&gt;
  
  
  &lt;strong&gt;LOAD&lt;/strong&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/iFhFPIbQEQ6GPIs4KY/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/iFhFPIbQEQ6GPIs4KY/giphy.gif" alt="gif of mongodb being loaded with a json dataset in a terminal" width="480" height="364"&gt;&lt;/a&gt;&lt;br&gt;
Now that we've installed and started our MongoDB, we need to populate it with data. We'll be using the dataset from the &lt;a href="https://github.com/ATL-WDI-Exercises/mongo-pokemon"&gt;&lt;code&gt;mongo-pokemon&lt;/code&gt;&lt;/a&gt; repository provided by &lt;a href="https://github.com/ATL-WDI-Exercises"&gt;ALT-WDI&lt;/a&gt;. To keep this simple, I've forked this repo and trimmed it down to the single dataset file we'll need. &lt;/p&gt;

&lt;p&gt;Make sure you have started your MongoDB instance then open your terminal, navigate to a clean directory, and run the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/jackkeck/pokemonDataSet
&lt;span class="nb"&gt;cd &lt;/span&gt;pokemonDataSet
mongoimport &lt;span class="nt"&gt;-d&lt;/span&gt; pokemon &lt;span class="nt"&gt;-c&lt;/span&gt; pokemons &lt;span class="nt"&gt;--jsonArray&lt;/span&gt; &amp;lt; pokemon.json
mongo
show dbs
use pokemon
show collections
db.pokemons.find&lt;span class="o"&gt;()&lt;/span&gt;.pretty&lt;span class="o"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Git's &lt;a href="https://git-scm.com/docs/git-clone"&gt;&lt;code&gt;clone&lt;/code&gt;&lt;/a&gt; command will copy my forked repository to your local machine. Once it's downloaded, you use &lt;a href="http://linuxcommand.org/lc3_man_pages/cdh.html"&gt;&lt;code&gt;cd&lt;/code&gt;&lt;/a&gt; to drop down into the repository.&lt;/p&gt;

&lt;p&gt;MongoDB's &lt;a href="https://docs.mongodb.com/manual/reference/program/mongoimport/"&gt;&lt;code&gt;mongoimport&lt;/code&gt;&lt;/a&gt; command allows us to bulk load data. In this case, we're using flags to accomplish a few things. We're creating a database called "pokemon" using the &lt;code&gt;-d&lt;/code&gt; flag. We're creating a collection called "pokemons" using the &lt;code&gt;-c&lt;/code&gt; flag. We're telling the import command to treat the data file as a &lt;a href="https://www.json.org/"&gt;JSON Array&lt;/a&gt;. Finally, we're specifying pokemon.json as our import file.&lt;/p&gt;

&lt;p&gt;MongoDB provides a Javascript-based shell through it's &lt;a href="https://docs.mongodb.com/manual/mongo/"&gt;&lt;code&gt;mongo&lt;/code&gt;&lt;/a&gt; command. Once we pop a shell, we're using the &lt;a href="https://docs.mongodb.com/manual/reference/mongo-shell/"&gt;&lt;code&gt;show dbs&lt;/code&gt;&lt;/a&gt; command to list all available databases to verify we've created the pokemon database. We &lt;code&gt;use&lt;/code&gt; the pokemon database then list its collections using &lt;a href="https://docs.mongodb.com/manual/reference/mongo-shell/"&gt;&lt;code&gt;show collections&lt;/code&gt;&lt;/a&gt;. We can see the "pokemons" collection was created so we use &lt;a href="https://docs.mongodb.com/manual/reference/method/db.collection.find/index.html"&gt;&lt;code&gt;db.pokemons.find().pretty()&lt;/code&gt;&lt;/a&gt; to check that the data was imported. I like to add the &lt;a href="https://docs.mongodb.com/manual/reference/method/cursor.pretty/index.html"&gt;&lt;code&gt;.pretty()&lt;/code&gt;&lt;/a&gt; method to make the output easier to read. For those of you who are familiar with relational databases and sql, this is the mongo equivalent of &lt;code&gt;select * from pokemon.pokemons&lt;/code&gt;.&lt;/p&gt;







&lt;h2&gt;
  
  
  &lt;strong&gt;SECURITY&lt;/strong&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;MongoDB and the security community have had an interesting relationship. Up until version 3.6, MongoDB used to allow any connection on port 27017 by default (meaning if you weren't behind a firewall, anyone could pop into your database). Even now, it still doesn't ship with any kind of access control or authentication enabled by default unless you have an enterprise-licensed version 💰. This section will walk through some basic steps we can take to protect our instance.  &lt;/p&gt;







&lt;h3&gt;
  
  
  &lt;strong&gt;ROLE-BASED ACCESS CONTROL&lt;/strong&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;As a rule, we should try to adhere to the principle of least privilege (PoLP). By applying this principle now, we're ensuring that we build our application with a level of access that we'll have in a production environment.&lt;/p&gt;

&lt;p&gt;MongoDB uses role-based access control (RBAC) to allow for the governance (er.... control) of access. There is a ton of material available on what RBAC is. If you're interested, here is &lt;a href="https://csrc.nist.gov/publications/detail/conference-paper/1992/10/13/role-based-access-controls"&gt;the definition from David Ferraiolo's and Richard Kuhn's conference paper &lt;em&gt;"Role-Based Access Controls"&lt;/em&gt;:&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;A role-based access control (RBAC) policy bases access control decisions on the functions a user is allowed to perform within an organization. The users cannot pass access permissions on to other users at their discretion.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;MongoDB does not ship with this enabled by default. In order to enable this, we need to:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a superuser. &lt;/li&gt;
&lt;li&gt;Enable &lt;code&gt;authorization&lt;/code&gt; in our &lt;code&gt;mongod.conf&lt;/code&gt;. &lt;/li&gt;
&lt;li&gt;Create a user with Read and Write (RW) access, but only to the pokemon database. &lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  &lt;em&gt;CREATE ADMIN USER&lt;/em&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/McUpUbMLNHwjFm0o3K/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/McUpUbMLNHwjFm0o3K/giphy.gif" alt="gif of creating an admin user for mongodb in terminal" width="480" height="364"&gt;&lt;/a&gt;&lt;br&gt;
A superuser has access to do anything and everything. You've been operating with this access this whole time by default. So let's create a dedicated admin user with a password. In your terminal, open a mongo shell and run the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;use&lt;/span&gt; &lt;span class="nx"&gt;admin&lt;/span&gt;

&lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;createUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; 
    &lt;span class="na"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;admin&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  
    &lt;span class="na"&gt;pwd&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;doNotEatThat&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="na"&gt;roles&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; 
      &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;userAdminAnyDatabase&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;db&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;admin&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dbAdminAnyDatabase&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;   &lt;span class="na"&gt;db&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;admin&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;readWriteAnyDatabase&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;db&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;admin&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;









&lt;h4&gt;
  
  
  &lt;em&gt;ENABLE AUTHORIZATION&lt;/em&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/MBNtB3E78GeCA0Rdyl/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/MBNtB3E78GeCA0Rdyl/giphy.gif" alt="gif of editing mongodb configuration to enable security authorization" width="480" height="364"&gt;&lt;/a&gt;&lt;br&gt;
Once the admin user is created, we need to enable the &lt;code&gt;security.authorization&lt;/code&gt; setting in MongoDB. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Stop MongoDB 
Run &lt;code&gt;pkill -f mongod&lt;/code&gt; to stop the database. You can confirm it has stopped using &lt;code&gt;jobs -l&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Update &lt;code&gt;mongod.conf&lt;/code&gt;
I used &lt;code&gt;sudo vi&lt;/code&gt;. For reference, use your arrow keys to get to the end of the file, press "i" on the keyboard to type, add the security block below, press "esc" on the keyboard, then type ":wq" then hit enter to save and exit.
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="s"&gt;/:~$ sudo vi /usr/local/etc/mongod.conf&lt;/span&gt;

&lt;span class="na"&gt;systemLog&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;destination&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;file&lt;/span&gt;
  &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;/usr/local/var/log/mongodb/mongo.log&lt;/span&gt;
  &lt;span class="na"&gt;logAppend&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="no"&gt;true&lt;/span&gt;
&lt;span class="na"&gt;storage&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;dbPath&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;/usr/local/var/mongodb&lt;/span&gt;
&lt;span class="na"&gt;net&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;bindIp&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;127.0.0.1&lt;/span&gt;
&lt;span class="na"&gt;security&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
   &lt;span class="na"&gt;authorization&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;enabled&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  &lt;em&gt;CREATE BASIC USER&lt;/em&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/J4Ij43gtosj1PWAVaE/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/J4Ij43gtosj1PWAVaE/giphy.gif" alt="gif of creating a basic user for mongodb in terminal" width="480" height="364"&gt;&lt;/a&gt;&lt;br&gt;
The basic user will have read and write access for &lt;em&gt;only&lt;/em&gt; the pokemon database. In your terminal, open a mongo shell and run the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;admin&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;doNotEatThat&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nx"&gt;use&lt;/span&gt; &lt;span class="nx"&gt;pokemon&lt;/span&gt;

&lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;createUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; 
    &lt;span class="na"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;misty&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  
    &lt;span class="na"&gt;pwd&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;godDamitPsyduck&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="na"&gt;roles&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; 
      &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;readWrite&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;db&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;pokemon&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;









&lt;h4&gt;
  
  
  &lt;em&gt;TRUST, BUT VERIFY&lt;/em&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/XBu8j8LPQB3WNqQn1m/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/XBu8j8LPQB3WNqQn1m/giphy.gif" alt="gif showing inability to perform actions mongodb without first authenticating " width="480" height="364"&gt;&lt;/a&gt;&lt;br&gt;
To verify your database is now governed using RBAC, try to connect and view something. You'll notice that when you initiate a connection using the &lt;code&gt;mongo&lt;/code&gt; shell, there is no longer a warning message stating "Access Control is not enabled for this database". Additionally, we're unable to view or edit anything until we authenticate using &lt;code&gt;db.auth("user","pwd")&lt;/code&gt;.&lt;/p&gt;







&lt;h4&gt;
  
  
  &lt;strong&gt;CHANGE DEFAULT PORT&lt;/strong&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/LPHQpKvJKUsIZSOD2A/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/LPHQpKvJKUsIZSOD2A/giphy.gif" alt="gif of editing the default port in mongod.conf using terminal" width="480" height="364"&gt;&lt;/a&gt;&lt;br&gt;
Starting in MongoDB 3.6, mongod is now configured to allow connections &lt;em&gt;only&lt;/em&gt; from localhost. This means that you can only access your instance from your laptop. That's excellent however IP's can be spoofed, etc. One extra step we'll take is to change the default MongoDB's default port. Similar to how we enabled &lt;code&gt;security.authorization&lt;/code&gt;, we'll update our &lt;code&gt;mongod.conf&lt;/code&gt;. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Stop MongoDB 
Run &lt;code&gt;pkill -f mongod&lt;/code&gt; to stop the database. You can confirm it has stopped using &lt;code&gt;jobs -l&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Update &lt;code&gt;mongod.conf&lt;/code&gt;
I used &lt;code&gt;sudo vi&lt;/code&gt;. For reference, use your arrow keys to get to the end of the file, press "i" on the keyboard to type, add the port setting below, press "esc" on the keyboard, then type ":wq" then hit enter to save and exit.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="s"&gt;/:~$ sudo vi /usr/local/etc/mongod.conf&lt;/span&gt;

&lt;span class="na"&gt;systemLog&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;destination&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;file&lt;/span&gt;
  &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;/usr/local/var/log/mongodb/mongo.log&lt;/span&gt;
  &lt;span class="na"&gt;logAppend&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="no"&gt;true&lt;/span&gt;
&lt;span class="na"&gt;storage&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;dbPath&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;/usr/local/var/mongodb&lt;/span&gt;
&lt;span class="na"&gt;net&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;port&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;23456&lt;/span&gt;
  &lt;span class="na"&gt;bindIp&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;127.0.0.1&lt;/span&gt;
&lt;span class="na"&gt;security&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
   &lt;span class="na"&gt;authorization&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;enabled&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now start your database back up. Please keep in mind that you will need to run `mongo --port 23456' when you launch you connect now.&lt;/p&gt;







&lt;h4&gt;
  
  
  &lt;strong&gt;HELPFUL SCRAPS&lt;/strong&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;DATABASE CLEANUP&lt;/strong&gt;&lt;br&gt;
To quickly wipe all databases &lt;em&gt;except admin&lt;/em&gt;, please use this nifty one-liner from the user &lt;a href="https://stackoverflow.com/users/348785/kev"&gt;kev&lt;/a&gt; as part of the &lt;a href="https://stackoverflow.com/a/16908246"&gt;MongoDB drop every database&lt;/a&gt; thread on Stack Overflow:&lt;br&gt;
&lt;code&gt;&lt;/code&gt;&lt;code&gt;bash&lt;br&gt;
mongo --quiet --eval 'db.getMongo().getDBNames().forEach(function(i){db.getSiblingDB(i).dropDatabase()})'&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;CLEAN UNISTALLL&lt;/strong&gt;&lt;br&gt;
To completely uninstall MongoDB and delete all of its tertiary data, please run the following commands:&lt;br&gt;
&lt;code&gt;&lt;/code&gt;&lt;code&gt;bash&lt;br&gt;
pkill -f mongod&lt;br&gt;
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist&lt;br&gt;
rm -f ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist&lt;br&gt;
launchctl remove homebrew.mxcl.mongodb &lt;br&gt;
brew uninstall --force mongodb-community &lt;br&gt;
brew untap mongodb/brew &lt;br&gt;
rm -rf /usr/local/etc/mongo*&lt;br&gt;
rm -rf /usr/local/bin/mong*&lt;br&gt;
rm -rf /usr/local/var/mongodb &lt;br&gt;
rm -rf /Users/$USER/Library/Caches/Homebrew/downloads/*mongodb*&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt; &lt;/p&gt;







</description>
      <category>mongodb</category>
      <category>beginners</category>
      <category>devops</category>
      <category>pokemon</category>
    </item>
    <item>
      <title>How to Install Atom.io on Chomebook</title>
      <dc:creator>Jack Keck</dc:creator>
      <pubDate>Sat, 12 Jan 2019 18:01:23 +0000</pubDate>
      <link>https://dev.to/jackkeck/how-to-install-atomio-on-chomebook-3e8i</link>
      <guid>https://dev.to/jackkeck/how-to-install-atomio-on-chomebook-3e8i</guid>
      <description>&lt;p&gt;&lt;b&gt;Assumptions&lt;/b&gt;&lt;br&gt;
You have a Linux-capable Chromebook. You can check &lt;a href="https://www.reddit.com/r/Crostini/wiki/getstarted/crostini-enabled-devices" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;br&gt;
You have already enabled Linux. You can follow instructions &lt;a href="https://www.androidpolice.com/2018/08/19/install-linux-applications-chrome-os/" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;My Environment&lt;/b&gt;&lt;br&gt;
Samsung Chromebook 3&lt;br&gt;
Linux enabled&lt;br&gt;
Google Chrome 72.0.3626.49 (Official Build) dev (64-bit) &lt;/p&gt;

&lt;p&gt;&lt;b&gt;Step 1 - Download Atom.io&lt;/b&gt;&lt;br&gt;
I downloaded the deb installer direct from &lt;a href="https://github.com/atom/atom/releases/tag/v1.34.0" rel="noopener noreferrer"&gt;Atom's Github releases page&lt;/a&gt;. You'll need to use the correct flags in your curl command in order to handle the inevitable redirects :: le sigh ::&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffbm0xjl4pl3k7cinw5dr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffbm0xjl4pl3k7cinw5dr.png" alt="curl command with flags"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Step 2 - Install Atom.io&lt;/b&gt;&lt;br&gt;
Installing is simple as opening your file browser, navigating down to My files &amp;gt; Linux files, then double clicking the deb installer file.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F078432tbo7yyx3t1ggws.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F078432tbo7yyx3t1ggws.png" alt="deb installer in file browser"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt; Step 3 - Launch Atom&lt;/b&gt;&lt;br&gt;
I prefer to launch directly from the directory I want to work from using the &lt;code&gt;atom .&lt;/code&gt; command. Although, you could also just search for Atom and launch that way.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8n7p13px3nt1sbvd2a7d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8n7p13px3nt1sbvd2a7d.png" alt="atom launched from terminal"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>atom</category>
      <category>samsungchromebook3</category>
      <category>chromebook</category>
      <category>chromeos</category>
    </item>
  </channel>
</rss>
