MongoDB Plugin for PyCharm
Tags: mongodb, pycharm, python
Published: 2017-08-19 00:33:41

---
title: MongoDB Plugin for PyCharm
published: true
description: The PyCharm IDE is a great tool for developing in the Python programming language. In this post let's look at the MongoDB Plugin tool.
tags: MongoDB, PyCharm, Python
cover_image: https://thepracticaldev.s3.amazonaws.com/i/46doq5tsxu2hdshphqxz.png
canonical_url: https://www.kenwalger.com/blog/nosql/mongodb/mongodb-plugin-pycharm/
---

There are many different options available when developing to look at and examine your <a href="https://www.mongodb.com">MongoDB</a> collections. MongoDB's <a href="https://www.kenwalger.com/blog/nosql/mongodb/mongodb-compass-an-overview/">Compass</a> is a great example of a tool that allows for the viewing and interaction with a database, collection, or document. However, when developing it is often useful to have the ability to see your data inside your development environment. Let's take a look at a useful MongoDB Plugin for PyCharm for viewing collections.
<h3>MongoDB Plugin</h3>
While I will be discussing the <a href="https://plugins.jetbrains.com/plugin/7141-mongo-plugin">Mongo Plugin</a> specifically as it relates to <a href="https://www.jetbrains.com/pycharm/">PyCharm</a>, the plugin itself works with the vast majority of IDEs provided by <a href="https://www.jetbrains.com/">JetBrains</a>. After downloading and installing the plugin we need to set a few things up. I'll walk through setting up connections for a local installation of a MongoDB server as well as a connection to their Database as a Service, <a href="https://www.kenwalger.com/blog/nosql/mongodb/mongodb-atlas/">Atlas</a>. For testing the connection we will want to make sure both of these servers are up and running.
<h4>MongoDB Plugin Settings</h4>
<h6>Local Server</h6>
For the local server, the settings are relatively straight forward. Assuming that we are working with a server on the default port of 27107, let's take a look at our settings.

<img class="wp-image-531 size-full" src="https://www.kenwalger.com/blog/wp-content/uploads/2017/08/plugin_settings_blank-e1503103697923.png" alt="MongoDB Plugin - Initial Setup" width="480" height="325" />

We see here that there is a place to input the path to ourÂ <em>Path to <a href="https://www.kenwalger.com/blog/nosql/mongodb-cli-tools/">Mongo Shell</a></em>. Be sure to put the location to the <code>mongo</code> executable and not the one for <code>mongod</code>.Â You can hit theÂ <strong>test</strong> button next to the path name to make sure the plugin is happy with the correct file.

We next need to add a server to use and connect with. By clicking on the <code>+</code> symbol we are presented with an option to configure our server connection.

<img class="size-full wp-image-535" src="https://www.kenwalger.com/blog/wp-content/uploads/2017/08/plugin_set_localhost.png" alt="MongoDB Plugin - Localhost setup" width="480" height="545" />

Here we see that we are able to label, or name, our connection and put in the server location in the format ofÂ <em>host:port</em>. For our example, we can use <code>localhost:27017</code>, as displayed above. For a single server without any authentication in place, these settings will connect to the database and you can seeÂ <strong>all</strong> of the databases on the server.

What if, however, you do have some authentication in place and want to establish a connection to a specific database? Let's examine that with a connection to an Atlas configuration.
<h6>Atlas Server</h6>
We will need our <a href="https://www.mongodb.com/cloud/atlas/">Atlas</a> connection URL that is available within our Atlas dashboard. Feel free to use your own server's host name or IP address. For my server settings, I want to set a read preference for the Primary node and to connect to the travel collection in the database.Â I also selected that I'd like it to use SSL for the connection.

<img class="size-full wp-image-541" src="https://www.kenwalger.com/blog/wp-content/uploads/2017/08/plugin_set_Atlas-1.png" alt="MongoDB Plugin - Atlas Connection" width="480" height="545" />

Since my Atlas server does require authentication, let's take a look at that tab.

<img class="size-full wp-image-540" src="https://www.kenwalger.com/blog/wp-content/uploads/2017/08/plugin_set_Atlas_auth-1.png" alt="MongoDB Plugin Authentication" width="480" height="545" />

We put in an appropriately established username and password along with the name of the <a href="https://docs.mongodb.com/manual/core/authentication/index.html">authentication</a> database. In this case, I am using the admin database. For Atlas, we want to choose the <a href="https://docs.mongodb.com/manual/core/security-scram-sha-1/#authentication-scram-sha-1">SCRAM-SHA-1</a> authorization mechanism. And then we can testÂ <em>this</em> connection. If everything is configured correctly, we should get the good news pop up.

<img class="size-full wp-image-532" src="https://www.kenwalger.com/blog/wp-content/uploads/2017/08/plugin_add_server_connection_succesful.png" alt="MongoDB Plugin Successful Configuration" width="220" height="128" />

<h4>Starting the Plugin</h4>
With our connections established, we can use the Mongo Explorer by navigating toÂ <em>View -&gt; Â Tool Windows -&gt; Mongo Explorer</em>. It will show our configured connections and when opening the connection up we see our databases listed.

<img class="wp-image-530 size-full" src="https://www.kenwalger.com/blog/wp-content/uploads/2017/08/mongo_plugin_once-e1503103727858.gif" alt="MongoDB Plugin Enabling" width="480" height="270" />

Upon selecting a given database we are given a list of the <a href="https://docs.mongodb.com/manual/core/databases-and-collections/">collections</a>. We can then choose a given collection and see a list of the documents in the collection.

<img class="wp-image-542 size-full" src="https://www.kenwalger.com/blog/wp-content/uploads/2017/08/plugin_collection_examination-e1503103745838.png" alt="MongoDB Plugin Examination" width="480" height="286" /> 

<h4>MongoDB Plugin ToolBar</h4>
If we have a look at the toolbar that appears above our collection:

<img class="aligncenter wp-image-543 size-full" src="https://www.kenwalger.com/blog/wp-content/uploads/2017/08/plugin_collection_examination_toolbar-e1503103763829.png" alt="MongoDB Plugin Toolbar callout" width="480" height="286" />

There are some great features in there.

<img class="aligncenter wp-image-544 size-full" src="https://www.kenwalger.com/blog/wp-content/uploads/2017/08/toolbar-e1503103779454.png" alt="MongoDB Plugin Toolbar" width="480" height="66" />

We see that we have a <code>find</code> option, an option to toggle the aggregation mode, and the ability to add and edit documents directly from PyCharm. We are given options to run queries withÂ <em>Filter</em>,Â <em>Projection</em>, andÂ <em>Sort</em> parameters as well. Â A group of very useful tools included with this plugin.
<h3>Wrap Up</h3>
With successfully configured connections to MongoDB servers, we can now utilize the Mongo Plugin to see what our data looks like as we develop. I personally find this to be aÂ <strong>huge</strong> benefit and time saver when developing. If you use a JetBrains IDE for your development, I would highly encourage you to have a look at this very useful plugin.

There are several MongoDB specific terms in this post. I created a <a href="https://www.echoskillstore.com/MongoDB-Dictionary/45103">MongoDB Dictionary</a> skill for the <a href="https://www.amazon.com/gp/product/B01DFKC2SO/ref=as_li_tl?ie=UTF8&amp;camp=1789&amp;creative=9325&amp;creativeASIN=B01DFKC2SO&amp;linkCode=as2&amp;tag=kenwalgersite-20&amp;linkId=f9e513223de2525a72b95cf9561db55b" rel="noopener noreferrer">Amazon Echo</a>Â line of products. Check it out and you can say "Alexa, ask MongoDB what is a document?" and get a helpful response.

<hr />

<em>Follow me on Twitter <a href="https://www.twitter.com/kenwalger">@kenwalger</a> to get the latest updates on my postings, or see the original post on my <a href="https://www.kenwalger.com/blog" target="_blank">blog</a>.</em>