-
Notifications
You must be signed in to change notification settings - Fork 0
Week1
#NOTES FROM THE COURSE
#Week 1: Introduction and Overview
We are going to build a blog engine, written in Java, which is connected to a MongoDB database. Since this course is a MongoDB cousre, most of the Java code is written for us, so we can concentrate on the database.
- Database: MongoDB
- Application:
- Spark framework: URL mapping, lightweight web framework
- Freemarker framework: Templating framework, we will use to create HTML templates with placeholders
- MongoDB Java driver
- Communicates with the database via TCP
- Non-rational database
- Stores JSON-s (actually BSON-s, which are the binary representation of JSON)
- Documents can have hierarchy: nested lists and dictionaries
- Schemaless
- Lightweight
MongoDB was designed to find a good compromise between functionality and scalability. Result: MongoDB scales better, than relational DBMS-es, but has less functionality (eg.: no joins, no transactions, BUT document modification is atomic)
We can access the DBMS directly (without drivers) via the mongo shell program, which has a JavaScript interface. You can start mongo shell by typing mongo
into the terminal.
Information about it's methods: http://docs.mongodb.org/manual/reference/method/
- Start MongoDB:
mongod --dbpath <path to directory>
(Changed the default data directory) - Start mongo:
mongo
(Connects to the default database, test)
Note to self:
echo $PATH
PATH=$PATH:<path to directory>
- List avaiable databases:
show dbs
(Empty databases are not displayed) - Change to database:
use <database name>
(Creates if not exsists) - Save new item:
db.<Collection name>.save(<JSON>)
- List all collections of the database:
show collections
Use TAB for autocompletion
- List items in a collection:
db.<Collection name>.find()
The documents we store in our database are placed in collections. A collection is like a table in a relational database, but it's schemaless and stores JSON documents instead of records.
We can see, that every item has an attribute called _id, it is a unique identifier, generated if not given, an index is built on it.
MongoDB stores JSON-s, which stands for JavaScript Object Notation. It is a commonly used data-interchange format, it's standardized.
Syntax: http://json.org/
- Using "" in the keys is not required (at least in MongoDB), but recommended
- {} -> valid JSON
- {"a" : {"a" : 1}} -> valid JSON
The 2 frameworks which we are going to use are:
- Spark
- Freemarker
- micro web framework for Java applications
- helps mapping URL-s
- it has a built-in webserver called Jetty
- info: http://sparkjava.com/
- Java template engine to generate text outputs based on templates
- we will use it to generate HTML outputs
- info: http://freemarker.org/index.html