Click here to Skip to main content
15,891,136 members
Articles / Programming Languages / Javascript
Tip/Trick

Hitching a Ride on the huMONGOus Meteor, Part 3 of 9

Rate me:
Please Sign up or sign in to vote.
4.50/5 (3 votes)
6 Aug 2015CPOL3 min read 9K   1
Part 3 of the 9-part series "As the Meteor Blazes" - Creating a MongoDB Collection

I Can Touch a Book, and for 30 Seconds, Know and Do Everything in the Book

MongoDB is one of those new-fangled (if you're old/have "been around awhile" it seems newfangled) types of databases called "No SQL" It's for "big data" (IOW, lots of data). If you're familiar with SQL databases, don't worry too much about the differences. Do keep in mind, though, a few terminology differences. What you relational database-heads think of as a "table" is called a "collection" in MongoDB-ese. Also, what you know as a "Row" is called a Document, and a "Column" is called a Field. So, instead of rows being made up of columns, and tables being comprised of Rows, documents are made up of Fields, and Collections are comprised of documents.

For musicians in the reading audience, you can think of the difference between a normalized relational database (such as MS SQL Server or Oracle) and a No-SQL database (such as MongoDB) as the difference between highly structured and predictable Classical music and flexible and improvisational Jazz.

So let's "jazz out" and dive right in, "playing it by ear" and learning as we go. Find your project's *.js file (at the same level as the .html and .css files edited earlier) and open it (in Notepad++ or whatever). Note that there is code there already (not empty like the .CSS file was)

Note that there are two conditional blocks, one for Client code, and one for Server code. Later, we'll see how these can be separated out into their own files for a separation of concerns/housekeeping, but for now we'll leave things as they are.

Remove the contents of the "isClient" block; that's the code that runs in the default minimal Meteor app.

Now, at the top of the .js file (not in the "isClient" or "isServer" block), add this code to create a Table, I mean a Collection:

JavaScript
TimeAndSpace = new Mongo.Collection('timeAndSpace');

This is likely easy enough to grok - we're creating a collection named "timeAndSpace" and assigning it to a global variable named "TimeAndSpace".

I Didn't Know it was Going to Look Like this, Pumpkin (note the comma (IOW, IMO, it looks nothing like a Pumpkin))

To verify your Collection has been created, in your Meteor app page (localhost 3000), open the console in your Dev Tools (mash F12), enter the name of the collection (TimeAndSpace), mash<enter>, and voila, you should see something like this:

Image 1

You can expand the down-arrows if you're curious to see some more metadata about the new Collection.

That's enough for now - we're set up with a Collection; in the next installment of "As the Meteor Blazes", we'll add some HTML in preparation for writing some data to the MongoDB Collection.

All Articles in the Series "Hitching a Ride on the HuMONGOus Meteor" (or, "As the Meteor Blazes")

PART 1: Installing Meteor, creating a Meteor project, and running the out-of-the-box Meteor Javascript App

PART 2: Making changes to the default HTML

PART 3: Creating a MongoDB Collection

PART 4: Creating the HTML to Receive Input from the User

PART 5: Writing MongoDB data

PART 6: Reading MongoDB Data and Displaying it on the page

PART 7: Gussying up/spiffifying the page with HTML and CSS

PART 8: Filtering and Ordering MongoDB Result Sets

PART 9: Meatier Meteor and MongoDB for Mutating Mavens

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Founder Across Time & Space
United States United States
I am in the process of morphing from a software developer into a portrayer of Mark Twain. My monologue (or one-man play, entitled "The Adventures of Mark Twain: As Told By Himself" and set in 1896) features Twain giving an overview of his life up till then. The performance includes the relating of interesting experiences and humorous anecdotes from Twain's boyhood and youth, his time as a riverboat pilot, his wild and woolly adventures in the Territory of Nevada and California, and experiences as a writer and world traveler, including recollections of meetings with many of the famous and powerful of the 19th century - royalty, business magnates, fellow authors, as well as intimate glimpses into his home life (his parents, siblings, wife, and children).

Peripatetic and picaresque, I have lived in eight states; specifically, besides my native California (where I was born and where I now again reside) in chronological order: New York, Montana, Alaska, Oklahoma, Wisconsin, Idaho, and Missouri.

I am also a writer of both fiction (for which I use a nom de plume, "Blackbird Crow Raven", as a nod to my Native American heritage - I am "½ Cowboy, ½ Indian") and nonfiction, including a two-volume social and cultural history of the U.S. which covers important events from 1620-2006: http://www.lulu.com/spotlight/blackbirdcraven

Comments and Discussions

 
GeneralMy vote of 5 Pin
gordon8812-Aug-15 10:33
professionalgordon8812-Aug-15 10:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.