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 8 of 9

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
11 Aug 2015CPOL1 min read 5.6K  
Part 8 of the 9-part series "As the Meteor Blazes" - Filtering and Ordering MongoDB Result Sets

But How Can You Complain When You Do Nothing?

You may have noticed some "bad" data being displayed in the HTML table in the previous installments of this series. Now, we will filter the query to ignore empty documents, and order by Year Arrived and then Year Departed (yearin and yearout)

To do so, replace the previous MongoDB query code:

Template.placesLived.helpers({
 	places: function () {
        // this helper returns a cursor of all of the documents in the collection
        return TimeAndSpace.find();
    }
});

...with this:

Template.placesLived.helpers({
 	places: function () {
        // this helper returns a cursor of all of the documents in the collection
	    return TimeAndSpace.find(
			{ts_city: {$exists: true, $ne: ""}, ts_state: {$exists: true, $ne: ""}},
			{sort: {ts_yearin: 1, ts_yearout: 1}}
		);
});

That's Because He was Wearing a Bullet-proof Vest!

Ain't that grand! Here is what the filtered and ordered collection looks like now:

The duplicates are still there; removing one of them is an exercise left to the reader (don't look at me), as is any baroquing or gingerbreading such as adding a map, with a pushpin for each location, perhaps numbered or with some other indication on it, such as certain colors to indicate duration of time spent in that spot, etc.

In the next and final installment of "As the Meteor Blazes", I will provide you with a plethora of poignant points and programatically lucrative links.

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

 
-- There are no messages in this forum --