Skip to main content

Mongo 101JS - Week 5

Hi everyone!

I've been home on stay-cation this week - really just a break from going to the day job. I intended to do a lot of things this week, but naturally most of those haven't happened. What has happened is I've gained a lot of 100% complete trophies on my PS3! lol It's been a good break overall, just always too short!

I did manage to stay on course with my mongodb class this week though! Our focus this week was on indexes. A lot of the information has felt like it was over my head - a lot of background information on how the database actually works. I feel like I've got vague understanding of things, but really what I'm wanting is more information on how to interact with it in programs. Which I've gotten some information on, just...not as much as I'd like.

I lost a good hour or so to the last homework problem this week. We were meant to import a sysprofile json document and query it for a specific query. Taking into account the type of file it was, I thought I needed to do a db.system.profile query to get the answer...and was getting nowhere. Nothing ever returned, and there doesn't seem to be a way to show that either the information isn't there or that a query is just running slow and still working. I tried soooo many times to change the wording, re-import the file, make sure I did everything in the right order....nothing.

What finally got me the right answer was to break down the mongoimport line they gave us. Here's the line:

mongoimport --drop -d m101 -c profile sysprofile.json

So, it looks like we're dropping the m101 database and the profile collection inside it, then importing the file. I ran this command for the 15th time, saw in the shell and on my mongod server that m101.profile was dropped, then started my mongo shell. When I did show dbs, the m101 database was still there! So I changed to that database, showed the collections, and the profile collection was still there! Seemed really weird to me. It was then that it hit me....maybe I'm meant to be running the query on this profile collection instead of the system profile!

So I did a basic find on the profile collection....and it showed the document I'd imported! I couldn't believe I'd read the homework description wrong this whole time. So I ran the requested query on db.profile, got the response I needed, and got the question right on the first try. lol

Ahhhh, the process of learning....never a dull moment!

Comments