MongoDB (Part 1): Getting Started

It has been a little while since I last played around with a NoSQL database on the blog.  Back in 2014, I wrote a few posts about CouchDB and over the years, I have done a bit with Firebase.  Today’s topic is going to be MongoDB.

The first step in this little adventure is going to be to set up a (free) shared instance.  Thanks to MongoDB Atlas, setting that up is ridiculously straight-forward.

All you need to do is visit the website, register, select the free plan, pick a cloud provider and region, and click “Create Cluster”.

Mongosh

The next step is to brew install mongosh on your workstation.  After that, you need to add your IP to the IP access list and then you can use mongosh to connect to the database.  Once you are connected to the database, you can use MongoDB’s mongosh usage guide to interact with your database.

TablePlus

Everybody loves a good command-line interface, but let us say that you want something a little easier?  I have mentioned TablePlus a few times before (mainly as an alternative to my beloved NaviCat).  Well, TablePlus is compatible with MongoDB.

All you need to do is to plug in the URL of the database (in my case mongodb+srv://username:password@cluster0.l5urt.mongodb.net/database), save the connection, and connect.

If you want to add another row to your database, you can use the “+ Row” button towards the bottom of the interface.

If you fill in the new row with data and command+s it, it save your new record to the database.

TablePlus definitely makes management of the database more painless but let’s try one more potential database client.

MongoDB Compass

MongoDB Compass is a free GUI client that boasts that you can “interact with your data with full CRUD functionality”.  Just like with TablePlus, you need to install the app, select “New Connection”, and then supply the “connection string”.  Unlike TablePlus, MongoDB Compass can’t handle special characters in your password.  The MongoDB website recommends that you just URL encode the password to deal with :, /, ?, #, [, ], and @ characters.

So, in this one, you can add another row by clicking “Add Document” and then “Insert Document”.

Where TablePlus represented data in a grid, Compass represents it as a block of JSON.  I’m not terribly sure which approach is the best but it seems to work pretty well.

 

Have a question, comment, etc?  Feel free to drop a comment, below.

 

[Cover photo by Jan Antonin Kolar on Unsplash ]

Leave a Reply

Your email address will not be published. Required fields are marked *