So You’ve downloaded MongoDB, you have a dataset and are ready to roll your sleeves up and start crushing some NoSQL projects. So what do you do first? If you’re like me, you need to understand what data you are working with. To help with that effort, here are 3 ways (probably more, but let’s keep it simple) to access and query data in MongoDB: 1) Mongo DB command line 2) Java 3) Toad Extension Eclipse For a quick introduction, I’m going to query a MongoDB collection called zips that was created in this blog post. There are several factors that make this challenging. First, the collection contains 29353 documents. Second, there are some embedded location details including lat/longitude information. To simplify things, I just want to find the zip code (which happens to be the _id field) of Manhattan, KS, the Little Apple! Let’s examine that process of finding that zip code for each of the 3 methods described above: 1) MongoDB Command Line – Barebones, but it works, and I can even add pretty() at the end of the line to print the result on multiple lines.: 2) Java – Requires a bit more upfront effort, but certainly more powerful when talking about web apps, so the complexity is a wash considering the flexibility…Material details of a class that queries my MongoDB collection, and the expected result highlighted below… 3) Toad Extension for Eclipse – This was by far the easiest option. Right now, this functionality is in pre-beta, so once its available I’ll go into more detail. Basically, what we see in the first screenshot is the use of the Filter fields (highlighted on the right). Here I’ve added free form text of ‘MANHATTAN’ and ‘KS’ to quickly narrow down from the original 29353 documents and show the single document highlighted in the left… …As you can see, if I remove the ‘city’ filter from the Right hand side, now only the ‘state’ filter is applied, and I see all cities in the state of ‘KS’ as the resulting set of documents on the left hand side… It’s also easy to handle nested or other elements by the inclusion of the ‘Detail’ column. Here I’ve chose to show fields ‘loc’ and ‘pop’ in the Detail view as highlighted here… …in this screenshot, I’ve added all fields to the Detail view for easier analysis. …and when I switch focus in the Grid view, the Detail view updates as well… So as you can see, there are many good options for getting insight into the structure of your MongoDB collections. That said, a 3 rd party tool like Toad Extension for Eclipse will make this effort much easier, and more intuitive as in contrast with the first two options, querying a collection in MongoDB with Toad Extension for Eclipse required exactly no knowledge of Java or MongoDB Query language. What that means is that anyone who knows a little bit about NoSQL can understand and filter datasets almost immediately with little to no instruction or prior knowledge.
↧