Authenticating to GitHub using SSH

You can use SSH to connect and authenticate to GitHub. This allows you to check-in your artifacts to GitHub from the CLI without having to provide your username and password during every git push. Here are some notes on how to enable SSH for GitHub.

Generating a new SSH key

Open Terminal.

Paste the text below, substituting in your GitHub email address.

ssh-keygen -t rsa -b 4096 -C ""

This creates a new ssh key, using the provided email as a label.

Generating public/private rsa key pair.

When you’re prompted to Enter a file in which to save the key, press Enter. This accepts the default file location.

 Enter a file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]

At the prompt, type a secure passphrase.

Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter same passphrase again: [Type passphrase again]

Adding your SSH key to the ssh-agent

Before adding a new SSH key to the ssh-agent to manage your keys, you should have checked for existing SSH keys and generated a new SSH key. When adding your SSH key to the agent, use the default macOS ssh-add command, and not an application installed by macports, homebrew, or some other external source.

Start the ssh-agent in the background.

eval "$(ssh-agent -s)"
Agent pid 4356

If you’re using macOS Sierra 10.12.2 or later, you will need to modify your ~/.ssh/config file to automatically load keys into the ssh-agent and store passphrases in your keychain.

Host *
 AddKeysToAgent yes
 UseKeychain yes
 IdentityFile ~/.ssh/id_rsa

Add your SSH private key to the ssh-agent and store your passphrase in the keychain. If you created your key with a different name, or if you are adding an existing key that has a different name, replace id_rsa in the command with the name of your private key file.

$ ssh-add -K ~/.ssh/id_rsa

Add the SSH key to your GitHub account

Copy the SSH key to your clipboard.

If your SSH key file has a different name than the example code, modify the filename to match your current setup. When copying your key, don’t add any newlines or whitespace.

$ pbcopy < ~/.ssh/
# Copies the contents of the file to your clipboard

Tip: If pbcopy isn’t working, you can locate the hidden .ssh folder, open the file in your favorite text editor, and copy it to your clipboard.

Now login to your GitHub account in a browser. In the upper-right corner of any page, click your profile photo, then click Settings.

In the user settings sidebar, click SSH and GPG keys.

Click New SSH key or Add SSH key.

In the Title field, add a descriptive label for the new key. For example, if you’re using a Mac, you might call this key “My Mac”. Paste your key into the “Key” field.

Click Add SSH key.

If prompted, confirm your GitHub password.

Switching remote URLs from HTTPS to SSH

Open Terminal.

Change the current working directory to your local project.

List your existing remotes in order to get the name of the remote you want to change.

git remote -v
origin (fetch)
origin (push)

Change your remote’s URL from HTTPS to SSH with the git remote set-url command.

git remote set-url origin

Verify that the remote URL has changed.

git remote -v
# Verify new remote URL
origin (fetch)
origin (push)

The .mongorc.js File

The .mongorc.js File

While working in MongoDB shell, if you are frequently wondering about which database you are working on, you can obviously find out typing ‘db’ at the command prompt. But if you are lazy like me, you can change your command prompt to reflect the database name by modifying the prompt function as follows:


prompt=function () {
 return db+'> ';


You can enhance this further to have the prompt display the current timestamp along with the database name to time your queries as follows:


prompt=function () {
 return db+':'+(new Date())+'> ';


If you get used to this and do not want to reprogram the prompt function every time you start your MongoDB shell, you can add a .mongorc.js file in your home directory and add the modified prompt function.

Now, every time you start your MongoDB shell, your prompt will show the database name and the current system time.

MongoDB Supported Data Types

November 23, 2013
MongoDB Supported Data Types

MongoDB adds support for a number of additional data types while keeping JSON’s essential key/value pair nature. Exactly how values of each type are represented varies by language, but this is a list of the commonly supported types and how they are represented as part of a document in the shell. The most common types are:


Null can be used to represent both a null value and a nonexistent field:

{“x” : null}


There is a boolean type, which can be used for the values true and false:

{“x” : true}


The shell defaults to using 64-bit floating point numbers. Thus, these numbers look “normal” in the shell:

{“x” : 3.14}


{“x” : 3}


For integers, use the NumberInt or NumberLong classes, which represent 4-byte or 8-byte signed integers, respectively.

{“x” : NumberInt(“3”)}

{“x” : NumberLong(“3”)}


Any string of UTF-8 characters can be represented using the string type:

{“x” : “foobar”}


Dates are stored as milliseconds since the epoch. The time zone is not stored:

{“x” : new Date()}

regular expression

Queries can use regular expressions using JavaScript’s regular expression syntax:”

“{“x” : /foobar/i}


Sets or lists of values can be represented as arrays:

{“x” : [“a”, “b”, “c”]}

embedded document

Documents can contain entire documents embedded as values in a parent document:

{“x” : {“foo” : “bar”}}

object id

An object id is a 12-byte ID for documents. See the section _id and ObjectIds for details:

{“x” : ObjectId()}

There are also a few less common types that you may need, including:

binary data

Binary data is a string of arbitrary bytes. It cannot be manipulated from the shell. Binary data is the only way to save non-UTF-8 strings to the database.


Queries and documents can also contain arbitrary JavaScript code:

{“x” : function() { /* … */ }}

Excerpt From

Kristina Chodorow. “MongoDB_ The Definitive Guide, 2nd Edition.epub.” iBooks.

Get Administrative Information regarding your MongoDB Server

November 23, 2013

By default MongoDB listens for socket connections on port 27017. The server will fail to start if the port is not available—the most common cause of this is another instance of MongoDB that is already running.
mongod also sets up a very basic HTTP server that listens on a port 1,000 higher than the main port, in this case 28017. This means that you can get some administrative information about your database by opening a web browser and going to http://localhost:28017.

Excerpt From

Kristina Chodorow. “MongoDB_ The Definitive Guide, 2nd Edition.epub.” iBooks.

MongoDB Subcollections

November 23, 2013

One convention for organizing collections is to use namespaced subcollections separated by the . character. For example, an application containing a blog might have a collection named blog.posts and a separate collection named blog.authors. This is for organizational purposes only—there is no relationship between the blog collection (it doesn’t even have to exist) and its “children.”
Although subcollections do not have any special properties, they are useful and incorporated into many MongoDB tools:
GridFS, a protocol for storing large files, uses subcollections to store file metadata separately from content chunks (see Chapter 6 for more information about GridFS).
Most drivers provide some syntactic sugar for accessing a subcollection of a given collection. For example, in the database shell, will give you the blog collection, and will give you the blog.posts collection.
Subcollections are a great way to organize data in MongoDB, and their use is highly recommended.

Excerpt From

Kristina Chodorow. “MongoDB_ The Definitive Guide, 2nd Edition.epub.” iBooks.