# Server-Side Scripting/Document Databases

This lesson introduces document database processing.
utiuu

## Objectives and Skills

Objectives and skills for this lesson include:
* Understand NoSQL database concepts
* Understand document database concepts
* Use a document database with server-side scripts

## Readings

* Wikipedia: NoSQL
* Wikipedia: Document-oriented database

## Multimedia

* Youtube: Node.js Crash Course Tutorial #9 - MongoDB
* Youtube: Node.js + Express - Tutorial - Insert and Get Data with MongoDB
* Youtube: Node.js + Express - Tutorial - Update and Delete Data with MongoDB

## Tutorials

Before trying to work with any database using a programming language, you should first be familiar with that database's command language. The following tutorials will be helpful in understanding how to use MongoDB.
* MongoDB
* W3Schools: MongoDB Tutorial
* TutorialsPoint: MongoDB Tutorial

## Examples

The following examples use MongoDB as the document database. A similar approach would work for almost any document-based database.
* Go
* Node.js (Express)
* PHP
* Python (FastAPI)
* Python (Flask)

## Activities

Complete the following activities using HTML, CSS, and a server-side scripting language. Apply best practices for user interface design and your selected scripting language, including modules, comments, indentations, naming conventions, and constants. Use HTML forms and input elements for input, server-side scripts for processing, and HTML elements for output. Use separate functions for each type of processing. Avoid global variables by passing parameters and returning results. Add comments at the top of the code modules and include references to any resources used. Add the completed code to your website as /lesson10.
* Create an application that allows the user to insert, update, and delete records in a document database. After each action, display the current records. Use any document database and data structure you like. Be sure to include date, text, and number field types in the data structure. If in doubt, any of the previous cyclone, earthquake, or wildfire activities may be used as data examples.

## Lesson Summary

Additional items may be contributed by course participants
* NoSQL databases are non tabular, and store data differently than relational tables. NoSQL databases come in a variety of types based on their data model. The main types are document, key-value, wide-column, and graph. They provide flexible schemas and scale easily with large amounts of data and high user loads.
* NoSQL databases are sometimes viewed as more flexible than relational databases.
* Significant terminology and usage differences between a document database and a relational database are important to understand. In a document database, a Document is similar to a Record containing a set of information for a particular item. Documents can each have a unique structure where Records in a relational database all have the same format. Documents are store in a Collection that is similar to a Table in a relational database.
* MongoDB is a document database that stores data in JSON-like documents. It supports arrays and nested objects as values.
* MongoDB requires and automatically adds a unique identifier field called _id to each document in the collection.
* MongoDB stores data records as documents (specifically BSON documents) which are gathered together in collections. A database stores one or more collections of documents.
* The $set operator replaces the value of a field with the specified value.
* Indexes can be added to MongoDB collections. Without them when queries are preformed MongoDB searches every document, but indexing can limit searches to relevant documents in some cases.

## Key Terms

Additional items may be contributed by course participants

### collection

    Equivalent to a table in relational databases.

### document (BSON)

    A data structure composed of field and value pairs.

## See Also

* Databases
* MongoDB
* Docker/Compose
* Guru99 Tutorial: How to Download & Install MongoDB on Windows