Mongo Starter

Elvenware Logo


In Class Mongo

In many cases, you will be asked to only do the first five or six steps in this assignment.

Step 1: Mongo Account

Create an account on MongoLab.

Step 2: Install Mongo on Linux

To install on Cloud 9:

mkdir data
echo 'mongod --bind_ip=$IP --dbpath=data --nojournal --rest "$@"' > ~/mongod
chmod a+x ~/mongod

Otherwise, follow the steps outlined in the Elvenware Install Mongo section to install MongoDb on your system. When you are done with the install, come back to this assignment.

Step 3: MongoTalk.json

Many of the MongoSamples use a JSON file called MongoTalk.json. To learn how to set it up, read the section of the JsObjects/Data README file that covers MongoTalk.json.

Step 04: Insert Data

Create a copy of JsObjects/Data/MongoCreateData. For instance, to create a copy in the Source directory:

cd ~/Source
cp -r ~/Git/JsObjects/Data/MongoCreateData/ .

NOTE: If ~/Source does not exist, then create it like this mkdir ~/Source.

Run npm install.

To learn how to use the program, see the README.

Step 05: View the data in the database

MongoDb ships with a client. Elvenware has a description of how to use it.

Step06: MongoLab URLs and Users

Unless you are using Mlab/MongoLab, you can skip this step.

Learn about them on Elvenware.

Step07: An Express Mongo Program

In some cases, we will move to another assignment and not complete this or the other steps in this assignment.

Main might start by looking like this:

      paths: {
        "jquery": "jquery-2.1.0",

    require(["jquery"], function(jq) {
        'use strict';
        console.log("Main called.");

Add in the Elvenware QueryMongo library to routes:

cd routes

Open QueryMongo.js and set the collectionName to lincoln.

Load the library into the index route:

var queryMongo = require('./QueryMongo').QueryMongo;

NOTE: The following assumes that you used the instructions above to create the lincoln collection in the test database.

And call readAll:

    //Read the collection
    router.get('/readAll', function(request, response) {'use strict';
        console.log("ReadAll route is called");

Step 08: Build the client

On the client side, create MongoClient.js:

define(function() {

    var MongoClient = (function() {

        function MongoClient() {


        return MongoClient;


    return MongoClient;


Add it in to Main.js.

Create a button click handler and use getJSON to pull your /readAll route.

Handle the data and display it to the user.

Turn it in

If you are in Prog 272, take a picture of MongoLab, showing any collection that you were able to insert into your database.

NOTE: Do not put your screen shot in a zip file or embed it in a word document. Simply attach the screen shot to your assignment when you turn it in.

If you are in Prog 219, attach a screenshot of the mongo client running in the bash shell and using find to show the contents of a collection you created. To start the mongo client, aka mongo shell, just type mongo at the bash shell. Then run a few commands such as show dbs, use test, show collections and then show the contents of a collection. For instance, take a screenshot showing the output of these or similar commands:

Sample output when starting the mongo shell:

$ mongo
MongoDB shell version: 3.2.7
connecting to: test
> show dbs
local          0.000GB
prog219-renew  0.000GB
renew          0.000GB
test           0.000GB


If you completed the whole assignment, you should also push your work to your repository.