Learning Node.js MongoDB: Part 1: Terminology and Comparison with SQL

Learning Node.js MongoDB

MongoDB is a popular NoSQL document-oriented database system. The Node.js driver allows for connecting to an existing MongoDB installation or system.


Background

For many years, the most popular database management systems were those based on the Structured Query Language (SQL). These were designed for operating on data sizes of dozens of records to hundreds of tables. However, with the rise of massive web applications and a need for faster overall operations, many SQL systems were not able to keep up with developmental needs.

Increasingly, a classification of systems named NoSQL have become popular. Instead of being based on relational models, these are based on others such as the document model where data is organized by documents in key-value relationships, which can return and process data across some common operations faster than the same operations in a relational database management system (RDBMS).

Terminology

MongoDB organizes data across different layers and concepts using JSON-like structures based on BSON (binary-encoded JSON).

Database: A container for collections. Most MongoDB installations have multiple databases.

Collection: A group of documents. Conceptually similar to a table in SQL.

Document: A group of fields. Conceptually similar to a row in a SQL.

Field: A key-value pair. Conceptually similar to a column in a SQL.

Comparison with SQL Functionality

Operations

OperationMongoDBSQL
CreateinsertOne(), insertMany()INSERT INTO
ReadfindOne(), find()SELECT… FROM
UpdateupdateOne(), updateMany()UPDATE.. WHERE
DeletedeleteOne(), deleteMany()DELETE FROM

Data Models

Working with MongoDB in Node.js takes place via callback functions. Based on specifying the database, collection, and then operation, the first argument passed to the callback function will always be an error value with the second the requested collection, document, or field.

As JavaScript objects, calls to operations like find() and insertOne() are also functions run from (and thus on) collection objects returned by other operations.