Using ‘Mongo Plugin’ with WebStorm
I’ve been playing with WebStorm. I’m a huge fan of IDE’s because of the ways that I can save time. Switching from program to program or having to take my hands off of home row is just wasted time to me. I’m always looking for a plugin for the latest tool that I’ve been using in order to streamline my processes.
The latest tool that I’ve started using is for MongoDB. As I’ve started to spend time working on back-end functionality and databases, I want to be able to integrate my database inspection and management into my IDE.
Enter Mongo Plugin. When I discovered this I was hopeful that it would enable me to run a local mongod instance with a single click instead of starting it in the command line every time.
Unfortunately, it was not to be. As it is a less well known plugin from an independent developer, there is not a lot of information to be found regarding how to set it up and use it. That being the case, I made my assumptions about how it works and started playing with it with dismal results.
The set up seemed promising. After restarting WebStorm, I was greeted with with a ‘Mongo Explorer’ window and a ‘Mongo’ default configuration. Great! All I need to do is set up my server and go play.
Not so fast. Clicking the Mongo default configuration did nothing. Actually it did something, but that something was this:
That was disappointing. Not only is there no real community for support, there is no FAQ, and the Github repository doesn’t really explain how to get started.
I had actually tried to install this plugin several weeks before really working with it. I just didn’t have time to figure it out until those few weeks after discovering it. Now that I had the time, I was not going to quit until I figured it out.
Even though I couldn’t do anything in ‘Edit Configurations,’ I was still able to open ‘Mongo Explorer’ and click the ‘Mongo Settings’ button.
At least that’s how I think that it’s supposed to work.
Well, it didn’t. Even now that there was a default setting, attempting to add a new configuration just led to the same result as before. So I decided to run
mongod in a terminal and see what would happen in WebStorm.
After much trial and error, I finally managed to create a few configurations, but they still did not run the mongo server as I had hoped. I tried deleting the default configuration and was thereafter unable to create new configurations. This path eventually led me to uninstalling and reinstalling WebStorm several times. After all this, I finally drew some conclusions which enabled me to consistently and predictibly elicit functionality from the plugin.
One of the key conclusions that I inferred was that the plugin has no ability to operate as a MongoDB server. By accepting that I would still have to run mongod externally, I was able to figure out that the plugin is primarily to examine the contents of connected mongo databases.
It turns out that Mongo Plugin can run mongod from WebStorm. In the tools menu, under external tools, there’s a Mongod menu item. Selecting it starts mongod, and it even used the correct –dbpath. I don’t know where it found that. I don’t think that I specified that path on this round of installations. Either it’s left from a previous installation or attempt, or the plugin finds existing databases.
Either way, WebStorm can run mongod, complete with controls as seen below:
If you are going to follow along, first, make sure that you have set up a default configuration. This can be accessed by clicking the wrench and gear in the Mongo Explorer window. Add a server by clicking the ‘+’ at the bottom of the window. Using the pictured parameters will work.
With mongod running in the background, right clicking on the default configuration, in this case, called General, and selecting ‘Refresh this server’ displays a tree of databases similar to this one. Double clicking any of the folders will show its contents.
Also, with a database or collection selected, clicking the Mongo Shell button opens a shell which allows the user to interact with the database. Execute commands with command-enter.
It is also at this time that we are able to edit a configuration, though I don’t, at this point, have any idea what to do with it.
The good news is that Mongo Plugin is not as broken as it would seem. It gives me the ability to examine my databases without leaving the IDE, and it even has a functionality that might prove useful one day. It was a little difficult to develop the mental picture of how this all comes together, but now that I have one, I am excited to have this tool in my arsenal.