UMass Lowell Dept. of Computer Science

COMP 4620 — GUI Programming II

Spring 2016 Semester, Section 201

Prof. Jesse M. Heines

Notes for Class No. 9

Kate Carcia Visit and Introduction to Using MongoDB with Your Projects

Thursday, February 18, 2016

A video of this class is (or will be) posted at:  http://echo360.uml.edu/heines2016/comp4620-201.html


Handouts and Materials

Links related to today’s class


Openings / Announcements / Reminders

LinkedIn Posting:  Gone in Six Seconds: Why I Passed on Your Résumé

For those of you who know Angular1 and want to look at Angular2


Address by Alumnae Kate Carcia


Class Notes

Related reading for this class:  GetMEAN: Chap. 5


Things to Note as You Work Through Simon Holmes’s Textbook

  1. when you use console.log for debugging, the messages show up in the nodemon window, not the browser console
  2. things went pretty smoothly for me through Chapter 6, but as soon as I hooked up my database in Chapter 7 I got very strange results from the geo location routines
  3. thus, it is important that you begin each chapter with fully working code from the previous chapter
  4. it is incredibly important that geo locations are entered to his 2-element array as [longtitude,latitude]

The “chicken and egg” problem revisited

Comments on lecture and lecture notes techniques are welcomed


Building a Data Model with MongoDB and Mongoose (Ch. 5, p. 120)

Reviewing what we’re doing (p. 121)

Approach (p. 121)

How things fit together (p. 122)

Step 1:  Install MongoDB (Appendix A, p. 393)

Step 2:  Install Mongoose (p. 123)

$ npm install --save mongoose

Step 3 and 4:  Add Mongoose to our application (p. 125)

  1. create file db.js in loc8r/app_server/models with the following content
  2. var mongoose = require( 'mongoose' ) ;

note:  this is file loc8r/app_api/models/db.js in the code on Holmes’s GitHub repository

  1. require this file in loc8r/app.js
  2. require( './app_server/models/db' ) ;

Step 5:  Restart the application or make sure you’re running nodemon to restart it automagically (p. 125)

Step 6:  Create the Mongoose connection (p. 125)

Steps 7 and 8:  Monitoring the connection with Mongoose connection events (p. 126)

  1. add the following statements to loc8r/app_server/models/db.js
    source:  https://github.com/simonholmes/getting-MEAN/blob/chapter-05/app_server/models/db.js
  1. when the application is restarted, you should see:

in the nodemon window

Steps 9 and 10:  Closing a Mongoose connection (p. 126-128)

  1. wrap the connection.close command in the following statements to loc8r/app_server/models/db.js
    source:  https://github.com/simonholmes/getting-MEAN/blob/chapter-05/app_server/models/db.js

  1. call the above function when an appropriate signal is detected

Note that “the nodemon listener is using process.once as opposed to process.on, as we only want to listen for the SIGUSR2 event once. nodemon also listens for the same event and we don’t want to capture it each time, preventing nodemon from working.”

The complete database connection file loc8r/app_server/models/db.js is shown in Listing 5.1 on p. 129


Modeling Data (pp. 130-134)

Where we’re going (p. 131)

Understanding Mongoose (pp. 131-133)

Documents and Schemas

sample document:

{
  "firstname" : "Simon",
  "surname" : "Holmes",
  _id : ObjectId("52279effc62ca8b0c1000007")
}

corresponding schema:

{
  firstname : String,
  surname : String
}

Choosing path names

The properties object

Eight schema types


A Word to the Wise

by Brett McLaughlin, PHP & MySQL: The Missing Manual, p. 137

PHP MM

 



This is document http://jesseheines.com:8080/~heines/91.462/91.462-2015-16s/462-lecs/lecture09.jsp.  It was last modified on Friday, August 26, 2022 at 4:09 PM.
Copyright © 2022 by Jesse M. Heines.  All rights reserved.  May be freely copied or excerpted for educational purposes with credit to the author.