Course Introduction - AdarshMaurya/mongodb-and-mogoose-for-node-getting-started GitHub Wiki
Course Introduction
Fundamentals of Mongoose for Node and MongoDB. The term NoSQL is commonly used to describe a group of nonrelational database systems. NoSQL databases have been growing in popularity over the past number of years, and of the various NoSQL offerings available to us, MongoDB seems to be the clear favorite. You may have considered using a NoSQL database such as MongoDB, Couchbase, Firebase, or one of the many other offerings for one of your development projects, but you may have also been uncomfortable or weary of a database with such a perceived lack of structure where a hard and fast schema is not required. If you're coming NoSQL from a relational database background, some of these concerns are understandable. Let's try and take a different look at some of these concerns now. Think of a database as an empty filing cabinet, whether that be a relational database system such as SQL Server or MySQL or a NoSQL database such as MongoDB. When filing data in a relational database, things are structured and rule based. Every record must match the table's schema design. This is not the case with MongoDB. Simply put, you can place whatever you want into that filing cabinet. That freedom is what causes some developers to be nervous about using a NoSQL database, such as MongoDB. They're used to having the database set the rules and their application maps to and adheres to those rules often through the use of an object relational mapper such as Entity Framework, PetaPoco, ORM Lite, and many others. The goal of this course is to give you the building blocks needed to develop great web applications using Mongoose to easily store data into and retrieve documents from MongoDB in a structured manner. You can still think of this as a filing cabinet full of documents, but one that has some rules and structure to it. I say some rules because with MongoDB, you still have the freedom to store whatever you want, even if you are using Mongoose. The Node.js demo application that we will be building throughout the remainder of this course will effectively illustrate setting up a Mongoose schema, building a model from that schema, and validating data.
Prerequisites
Let's get started by going over some course prerequisites. While not completely required to gain benefit from this course, a general knowledge and understanding of Node.js and MongoDB would be helpful. Pluralsight offers excellent introductory courses on both MongoDB and Node.js. Links to those courses have been provided here. JavaScript, Node.js, and MongoDB all go hand in hand, so some experience with JavaScript is also needed to get the most from this course. Beyond that, the only other requirement is a willingness to explore and learn something new. So let's get started learning about Mongoose.
Why Mongoose?
If you have looked into using MongoDB on a development project or even if you've only seen a demo of it, there is a good chance that you've either used or have watched some else use a native MongoDB driver or that you're at least aware of it. There are official MongoDB drivers for many development languages such as C++, C#, Java, Perl, PHP, Python, Ruby, and of course, Node.js, which is what we will be focusing on in this course. So why then would we not just use the native Node.js MongoDB driver? Depending on the specific needs of your development project, there may be times when you do want to use the native Node.js driver. To find out more, visit this URL. A look at the mongoosejs.com website's home page may give us some insights into some valid reasons to use Mongoose over the native Node.js MongoDB driver. Quote, "Mongoose provides a straightforward, schema-based solution to model your application data. It includes built-in typecasting, validations, query building, business logic hooks, and more out of the box." When making the choice to use Mongoose, you are ultimately utilizing the native Node.js driver for MongoDB as well. Mongoose is built on top of and relies on this driver to talk to the underlying MongoDB document database. Mongoose is an abstraction layer on top of the native driver's functionality, and as you know, abstraction layers, generally speaking, are there to make your programming life easier. Is that always true? Probably not. There is not a single best answer of why you should use or not use Mongoose in your application. But as you move forward through this course, the goal is that you will gain enough knowledge to know when to use Mongoose and when it may be best to use a native MongoDB driver. Since this course is on Mongoose, naturally, we have already made the decision to use the Mongoose object-document mapper for our demo application. Speaking of the demo application, let's take a look at that next.
Demo Application Introduction
As we move through the course, we will be building a small demo application that will be used to demonstrate and reinforce each topic. In the next clip, we will take a peek at the complete and ready-to-go demo application. For now, let's talk about what its purpose is. We will be building a Node.js application to store virtual standup notes. This will be similar to what you may be familiar within scrum or agile daily standup meetings where everyone gathers around and recites what they worked on yesterday, what they plan on working on today, and if they've experienced any blockages or impediments. Our demo application will log the same information, but will allow for teams to hold virtual standup meetings. Team members will be able to enter daily meeting notes at their convenience rather than meeting face to face in a conference room. The architectural approach that we will take for this demo project at a high level is to separate the user interface components from our backend services, such as our RESTful API, which will be responsible solely from getting data from and sending data to the database, and of course, to our front-end components. This will provide us with a good degree of separation of concerns. For the UI side of things for this demo app, we will be using Vue.js. And if you're not familiar with Vue.js, don't be concerned. The bulk of our development work through this course will be focused on the API side of things, and that is where we'll be using Mongoose. After completing this course, should you want to learn more about Vue.js, take a look at these courses offered on Pluralsight or just search for all Vue.js related courses at this URL.
Demo: Preview of the Demo Application
Now let's take a look at what our virtual standup notes demo application will look like at the conclusion of this course. Here we are in our demo application that we've named virtual standup notes. The MongoDB server is running locally in the background, and some sample data has already been added. We'll also need to start our Express API server by running yarn start at the Command Prompt. We'll be using yarn throughout this course, but feel free to use npm as well. Next, we will run the Vue.js web application by entering yarn serve here on a new Command Prompt tab. That kicks off the webpack build process and spins up a local web server for us. This application is meant to be very minimalistic so that we can focus as much as possible on Mongoose. Nevertheless, we still want to build upon a sound architectural foundation and also have an application that looks good and is usable. And as mentioned earlier, we will be using Vue.js and Vuetify, a Material Design library, to accomplish this on the UI side of things. On the home page here, you can see that we will be showing a list of meeting notes, the newest 12 only. When we dig into the code, you will learn how easy it is in Mongoose to build such queries. Also, on the home page here, we can see that we'll be adding in the ability to filter down the list by selecting a member's name. Say I want to only see my own standup meeting notes. I can select Mark from the list and filter down the results. Again, we'll see in code how easy Mongoose makes this possible for us. On the new note page, we can see the data entry from we will be using to save new notes to MongoDB through a Mongoose model that we will develop. What you may see missing from this form is a Date field. On the home page, we said that we will be displaying a list of the most 12 recently entered in notes. So where's that date value coming from? In the Mongoose schema that we will develop in this course, you will learn how to set up default values. In this case, we have defaulted the date of the note to the current date, so there's no need in this case to ask the user for it. Again, to keep things simple and keep the focus of this course on Mongoose, you'll notice that we do not have any authentication in place. The user is not required to log in. Members of a team will just simply select their name from a drop-down list; select a project that they are a member of or that they're currently working on; and enter what they did yesterday, what they're planning on working on today, and if they have any impediments; and then click Save.