🌍 NodeJS · subject
NodeJS Database Integration Syllabus
Every chapter and topic of Database Integration examined in NodeJS — 2 chapters, 6 topics, plus 50 flashcards written against it.
Database Integration syllabus — full chapter and topic list
Expand any chapter to see its topics and sub-topics. This is the whole examinable outline for Database Integration in NodeJS, not a summary of it.
-
MongoDB
3 topics- Setting Up MongoDB
- Mongoose ODM
- CRUD Operations
-
SQL Databases
3 topics- MySQL
- PostgreSQL
- Sequelize ORM
Database Integration flashcards for NodeJS
25 of 50 cards from the Database Integration deck — real questions with worked answers.
What is MongoDB, and what data model does it use?
MongoDB is an open-source, document-oriented NoSQL database. It stores data as flexible, schema-less JSON-like documents in BSON (Binary JSON) format, grouped into collections rather than tables.
In MongoDB terminology, what are the equivalents of a relational table, row, and column?
Table -> Collection; Row -> Document; Column -> Field. A database contains collections, and collections contain documents made of field-value pairs.
What is the default port on which a MongoDB server (mongod) listens?
Port 27017.
What is the standard MongoDB connection string (URI) format for connecting from Node.js?
mongodb://[username:password@]host:port/database, or for Atlas the SRV form mongodb+srv://user:pass@cluster.mongodb.net/database.
What official Node.js package is the native MongoDB driver, and how do you install it?
The 'mongodb' package. Install with npm install mongodb. It provides MongoClient to connect and interact with the database directly (without an ODM).
What is Mongoose?
Mongoose is an ODM (Object Data Modeling) library for MongoDB and Node.js. It provides schema-based modeling of application data, including built-in type casting, validation, query building, and middleware (hooks).
What is the difference between an ODM and an ORM?
An ORM (Object-Relational Mapper) maps objects to relational/SQL tables (e.g., Sequelize). An ODM (Object-Document Mapper) maps objects to document databases like MongoDB (e.g., Mongoose). Both abstract raw queries into object operations.
In Mongoose, what is a Schema and what is a Model?
A Schema defines the structure, field types, defaults, and validation for documents in a collection. A Model is a compiled constructor built from a Schema (via mongoose.model()) that provides an interface to create and query documents of that collection.
How do you connect to MongoDB using Mongoose?
With mongoose.connect(uri), e.g. await mongoose.connect('mongodb://localhost:27017/mydb'). It returns a promise and manages a connection pool internally.
By default, what collection name does Mongoose derive from a model named 'User'?
'users' — Mongoose automatically lowercases and pluralizes the model name to determine the collection name.
What are the four CRUD operations and their typical MongoDB/Mongoose method families?
Create (insertOne/insertMany, Model.create/save), Read (find, findOne, findById), Update (updateOne, updateMany, findByIdAndUpdate), Delete (deleteOne, deleteMany, findByIdAndDelete).
In Mongoose, what is the difference between Model.create() and new Model() + save()?
Model.create(doc) instantiates and saves in one call, returning the saved document(s). new Model(doc) only builds an in-memory document; you must call .save() to persist it. Both run validation and middleware.
What does Mongoose's findByIdAndUpdate() return by default, and how do you get the updated document instead?
By default it returns the original (pre-update) document. Pass the option { new: true } to return the modified document.
What is the _id field in a MongoDB document, and what type is it by default?
_id is the mandatory unique primary key of every document. By default it is an ObjectId — a 12-byte value ($12$ bytes = $96$ bits) that is auto-generated if not supplied.
How is a MongoDB ObjectId's 12 bytes composed?
A 4-byte timestamp (seconds since Unix epoch), a 5-byte random value unique to the machine/process, and a 3-byte incrementing counter. Total $4 + 5 + 3 = 12$ bytes.
In a Mongoose query, what do the operators $gt, $lt, and $in mean?
$gt = greater than, $lt = less than, $in = matches any value in a given array. Example: { age: { $gt: 18 } } finds documents where $\text{age} > 18$.
What is the runValidators option in a Mongoose update, and why is it needed?
Schema validators do NOT run on update operations by default. Passing { runValidators: true } forces Mongoose to validate the update against the schema during findByIdAndUpdate / updateOne, etc.
What is Mongoose 'populate' used for?
populate() replaces a stored reference (an ObjectId in a ref field) with the actual document(s) from the referenced collection, simulating a SQL join across MongoDB collections.
What are Mongoose middleware (hooks), and name the two main kinds?
Middleware are functions that run at specified stages of a document's lifecycle. Pre hooks run before an operation (e.g., pre('save') to hash a password); post hooks run after (e.g., post('save') for logging).
What is MySQL, and what query language does it use?
MySQL is a popular open-source relational database management system (RDBMS) that stores data in tables with fixed schemas and uses SQL (Structured Query Language) for defining and manipulating data.
What is the default port for a MySQL server?
Port 3306.
Which two Node.js packages are commonly used to connect to MySQL, and what key feature does mysql2 add?
'mysql' and 'mysql2'. mysql2 is faster, supports prepared statements, and provides a built-in Promise API (mysql2/promise), making it the modern default.
What is a SQL prepared (parameterized) statement, and why use it?
A prepared statement sends the SQL structure and the parameter values separately (e.g., using ? placeholders). It prevents SQL injection and can improve performance by letting the server reuse the query plan.
What is a connection pool, and why is it important in a Node.js database app?
A connection pool is a cache of reusable open database connections. Instead of opening/closing a connection per query, the app borrows and returns connections, reducing latency and overhead under concurrent load.
What is PostgreSQL?
PostgreSQL (Postgres) is an advanced, open-source object-relational database (ORDBMS) known for standards compliance, extensibility, ACID transactions, and rich types like JSONB, arrays, and custom types.
Planning Database Integration for NodeJS
Database Integration is about 8% of the NodeJS syllabus by topic count — 6 of 72 topics, spread over 2 chapters. At roughly 45 minutes per topic plus 12 minutes per sub-topic, a first pass runs to about 5 hours.
Work top-down: read the chapter, then tick topics off individually rather than marking the whole chapter done. Sub-topics are where silent gaps hide.
Database Integration (NodeJS) FAQ
What is in the NodeJS Database Integration syllabus?
Database Integration is split into 2 chapters — MongoDB and SQL Databases, containing 6 topics and 0 sub-topics in total.
How is Database Integration structured in the NodeJS syllabus?
2 chapters. Database Integration accounts for about 8% of the topics in the whole NodeJS syllabus (6 of 72).
How long should I spend on Database Integration for NodeJS?
Budget around 5 hours for a first pass through Database Integration — about 45 minutes per topic plus 12 minutes per sub-topic across its 6 topics. Add revision cycles on top.
Are there flashcards for NodeJS Database Integration?
Yes — a 50-card Database Integration deck. Sample cards are printed on this page, and the full deck is free in the Examius app with spaced repetition scheduling.