<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://homeostasis.scs.carleton.ca/wiki/index.php?action=history&amp;feed=atom&amp;title=WebFund_2015W_Lecture_12</id>
	<title>WebFund 2015W Lecture 12 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://homeostasis.scs.carleton.ca/wiki/index.php?action=history&amp;feed=atom&amp;title=WebFund_2015W_Lecture_12"/>
	<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=WebFund_2015W_Lecture_12&amp;action=history"/>
	<updated>2026-05-12T22:19:38Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=WebFund_2015W_Lecture_12&amp;diff=19937&amp;oldid=prev</id>
		<title>LeeCroft at 22:43, 4 March 2015</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=WebFund_2015W_Lecture_12&amp;diff=19937&amp;oldid=prev"/>
		<updated>2015-03-04T22:43:17Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;a href=&quot;https://homeostasis.scs.carleton.ca/wiki/index.php?title=WebFund_2015W_Lecture_12&amp;amp;diff=19937&amp;amp;oldid=19878&quot;&gt;Show changes&lt;/a&gt;</summary>
		<author><name>LeeCroft</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=WebFund_2015W_Lecture_12&amp;diff=19878&amp;oldid=prev</id>
		<title>Soma: Created page with &quot;==Video==  The video from the lecture given on February 23, 2015 [http://homeostasis.scs.carleton.ca/~soma/webfund-2015w/lectures/comp2406-2015w-lec12-23Feb2015.mp4 is now ava...&quot;</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=WebFund_2015W_Lecture_12&amp;diff=19878&amp;oldid=prev"/>
		<updated>2015-02-23T17:27:50Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;==Video==  The video from the lecture given on February 23, 2015 [http://homeostasis.scs.carleton.ca/~soma/webfund-2015w/lectures/comp2406-2015w-lec12-23Feb2015.mp4 is now ava...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Video==&lt;br /&gt;
&lt;br /&gt;
The video from the lecture given on February 23, 2015 [http://homeostasis.scs.carleton.ca/~soma/webfund-2015w/lectures/comp2406-2015w-lec12-23Feb2015.mp4 is now available].&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&lt;br /&gt;
===On-Screen Notes===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Lecture 12&lt;br /&gt;
----------&lt;br /&gt;
&lt;br /&gt;
Midterms to be returned Wednesday&lt;br /&gt;
&lt;br /&gt;
Today: MongoDB and databases&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Parts of a web application:&lt;br /&gt;
* Front End: client-side code (HTML, CSS, JavaScript)&lt;br /&gt;
  - runs in the browser&lt;br /&gt;
* Back End: server-side code&lt;br /&gt;
  - web server: PHP, Python, Java, *JavaScript* (node)&lt;br /&gt;
  - database: MySQL, Oracle, PostgresQL, MongoDB, ...&lt;br /&gt;
&lt;br /&gt;
Early web servers just used a filesystem&lt;br /&gt;
 - good for static content&lt;br /&gt;
 - bad for concurrent access&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Why concurrency?&lt;br /&gt;
 - many different web clients trying to modify the &amp;quot;same&amp;quot; resources&lt;br /&gt;
 - e.g., passwords stored in a file&lt;br /&gt;
 - *really* bad when using multiple web servers&lt;br /&gt;
&lt;br /&gt;
Databases are good at&lt;br /&gt;
 - fine-grained data concurrency&lt;br /&gt;
 - not as easy to &amp;quot;scale&amp;quot; (cause concurrency is hard)&lt;br /&gt;
 - that&amp;#039;s SOMEBODY ELSE&amp;#039;s PROBLEM&lt;br /&gt;
&lt;br /&gt;
Why not just have web clients talk to the database?&lt;br /&gt;
 (cut out the middle man)&lt;br /&gt;
 - security: don&amp;#039;t want all clients to access ALL data&lt;br /&gt;
    - databases do have access control but generally not suitable for most web applications&lt;br /&gt;
    - also, data validation&lt;br /&gt;
 - scalability&lt;br /&gt;
    - databases are relatively slow&lt;br /&gt;
    - often stick a caching layer in front/separate out static content&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Types of databases&lt;br /&gt;
------------------&lt;br /&gt;
SQL versus NoSQL databases&lt;br /&gt;
&lt;br /&gt;
Actually, many kinds of NoSQL databases&lt;br /&gt;
&lt;br /&gt;
Difference is *transactions*&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SQL =&amp;gt; relational databases&lt;br /&gt;
&lt;br /&gt;
Data is divided into tables&lt;br /&gt;
&lt;br /&gt;
tables have columns (fields) and rows (records)&lt;br /&gt;
&lt;br /&gt;
Columns have types (date, string, number, etc)&lt;br /&gt;
&lt;br /&gt;
Table for customers&lt;br /&gt;
fields (columns)&lt;br /&gt;
 - Customer ID (primary key)&lt;br /&gt;
 - name&lt;br /&gt;
 - street&lt;br /&gt;
 - city&lt;br /&gt;
 - province&lt;br /&gt;
 - etc.&lt;br /&gt;
&lt;br /&gt;
Table for invoices&lt;br /&gt;
 - Invoice ID (primary key)&lt;br /&gt;
 - Customer ID&lt;br /&gt;
 - what they purchased&lt;br /&gt;
 - amount&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Relations connect tables&lt;br /&gt;
&lt;br /&gt;
Relations often work best with unique keys&lt;br /&gt;
 - fields where every record has a unique value&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Scenario&lt;br /&gt;
 - creating first invoice for a new customer&lt;br /&gt;
 - problem: system crashes after adding the invoice but before adding the customer&amp;#039;s info&lt;br /&gt;
 - transaction is what makes sure this never happens&lt;br /&gt;
   - if just an invoice or a customer change, transaction is not complete and data is thrown away&lt;br /&gt;
&lt;br /&gt;
Transaction:&lt;br /&gt;
 - start transaction&lt;br /&gt;
 - make your changes&lt;br /&gt;
    - add the invoice&lt;br /&gt;
    - add the customer&lt;br /&gt;
 - commit transaction if all changes succeeded, otherwise abort&lt;br /&gt;
&lt;br /&gt;
Relational databases have *overhead* and *complexty* and *security issues*&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
NoSQL =&amp;gt; no transactions&lt;br /&gt;
&lt;br /&gt;
We&amp;#039;re using MongoDB&lt;br /&gt;
 - &amp;quot;document store&amp;quot;&lt;br /&gt;
 - i.e., JSON store (Technically, BSON)&lt;br /&gt;
 - no built-in relations&lt;br /&gt;
 - however, MongoDB can run code...JavaScript&lt;br /&gt;
&lt;br /&gt;
In SQL databases&lt;br /&gt;
 - fields are pre-defined and relatively rigid&lt;br /&gt;
&lt;br /&gt;
In MongoDB&lt;br /&gt;
 - can have any properties in any document&lt;br /&gt;
 - no consistency requirement&lt;br /&gt;
&lt;br /&gt;
Indexing&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 - records/documents are stored in order of primary keys&lt;br /&gt;
    - fast to find by primary key&lt;br /&gt;
 - what if I want to find records/documents by something that *isn&amp;#039;t* a primary key&lt;br /&gt;
    - e.g., invoices by what was purchased, customers by city&lt;br /&gt;
&lt;br /&gt;
basic search&lt;br /&gt;
 - if sorted, then you do binary search&lt;br /&gt;
 - maybe store so you can index into an arry/hash table&lt;br /&gt;
 - otherwise...exhaustive search&lt;br /&gt;
&lt;br /&gt;
Indexing is a way to get around exhaustive search&lt;br /&gt;
&lt;br /&gt;
An index is a data structure associating:&lt;br /&gt;
 * a field or fields with&lt;br /&gt;
 * the primary key&lt;br /&gt;
&lt;br /&gt;
Index by city in customers&lt;br /&gt;
 - sorted list of cities and customer IDs&lt;br /&gt;
&lt;br /&gt;
Why not index on every field?&lt;br /&gt;
 - space&lt;br /&gt;
 - time of insert/add operation&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Soma</name></author>
	</entry>
</feed>