Explore the Marvel Universe with MongoDB and CenturyLink Cloud

Erik Arneson

April 8, 2014

Share +

Marvel recently opened up an API for its character and comic data, which includes all of the characters, what comics they appear in, and a lot more. After poking around with it for a little while, I decided I wanted a more visual way to explore the characters and the comics, and that this would be a great project to build off of MongoDB and CenturyLink Cloud. We could use graph search to explore the relationship between characters and comics, as well as full text search to explore the data.

This project was pretty fast to build. It took a little time to import the data from the Marvel API and to do the design and frontend work, but the actual backend code and database work was really fast (less than a day or so).

What we’re building

A node.js app for searching and viewing all the Marvel Comics data. Since Marvel’s API is rate limited, we’ll store all the data in MongoDB and periodically update it from the API. It took some time to get the data from Marvel’s API and I won’t go over that part here, but if you want to download the cached data, I’ve included a dump of it in the repo.

Getting data from MongoDB is super easy. This will return the data stored at the key we pass in. But we want to get more than just the character data. We also want to see the comics that the character appears in. You can see the getComicsByCharacter call.

Full Text Search

Now we can view a character, but how about searching? MongoDB supports full text search as of version 2.4. This allows us to do a full search across any text-based field we decide to index. To use this powerful feature, connect to the database server with this command from your server shell.

Back to our query, our search form will pass a few parameters. The getCharacters function is already set up to process different parameters using special MongoDB keywords like $regex.

Comics

The process to get a comic or search through them is very similar. Take a look at the source code on GitHub to learn more about searching for comics.

Next steps

Now our app can view and search. We use full-text search to find comics and characters, but what else could we do? What about seeing which characters appear in comics together, or seeing which villains have appeared in the most comics? There’s a lot more we could do with this data. Enjoy!