This is an introductory lecture on MongoDB. We follow the structure of the book:
Between MongoDB and PostgreSQL/MySQL/…, one will have to make a choice. For JavaScript/NodeJS, online resources and documentations have indicated that MongoDB is the popular tool of choice. It is important that we understand some of the characteristics of MongoDB that makes it attractive for certain designs. These are the followings:
In the long run, it is critically important to keep track of performance of your database performance.
Instructions for installing MongoDB directly on Windows or Linux-based environments can be found in MongoDB Documentation. However, MongoDB’s rolling versions can be problematic for production setup, as technical issues shown in previous versions of class lectures.
In our case, we will freeze all versions of NodeJS and MongoDB through containerization.
webappwebdb
webdb and select Open in terminal:
mongosh from the terminal.
Go through Unit 3, Lesson 13 of the textbook. One important thing to keep in mind is that this book uses the local MongoDB installation, hence `dbRURL = “mongodb://localhost:27017”.
For this class, with the container structure, we are assuming a remote MongoDB server located on node webdb. You will need to change the dbURL value accordingly:
1
dbURL = "mongodb://webdb:27017",
Mongoose is an Object Data Modeling (ODM) library that sits between your JavaScript/Node.js code and MongoDB.
Mongoose allows developers to define schemas for NodeJS.