Description
Course info
Rating
(12)
Level
Intermediate
Updated
Jul 18, 2017
Duration
1h 45m
Description

The core Node.js libraries that you use to develop web applications change often, and it may be challenging to keep up and implement those improvements. In this course, Moving Forward with Mongoose.js, you'll learn about breaking changes when upgrading from Mongoose version 3 to version 4. First, you'll dive into a whirlwind review of an introduction to Mongoose for Node.js and MongoDB course. Next, you'll build upon that review and you'll learn about updates and improvements in Mongoose version 4. Finally, you'll discover the latest features that Mongoose version 4 has to offer. When you’re finished with this course, you'll have a better understanding of how to move forward in Mongoose version 4, where to find additional information on all breaking changes, and have the knowledge to confidently utilize the new features, improvements, and more advanced topics.

About the author
About the author

Mark Scott is an experienced software developer with more than fifteen years experience in IT. He is currently the Manager of Software Development for a small group of talented web developers.

More from the author
Introduction to MEAN.JS
Intermediate
2h 6m
5 Jun 2015
Section Introduction Transcripts
Section Introduction Transcripts

Course Overview
Hello everyone. My name is Mark Scott, and welcome to my course Moving Forward with Mongoose. I am a software development team lead at AutoAlert and Pluralsight author. In this course, we are going to explore what you may encounter when moving forward from Mongoose version 3 up to version 4. Some of the topics that we will cover include breaking changes in Mongoose 4 from previous versions, new features and improvements in Mongoose 4, extending functionality with plug-ins, middleware and hooks, discriminators, and using promise libraries in Mongoose. By the end of the course, you should feel more comfortable moving forward with Mongoose and upgrading to version 4, and if you've done so already, there's still a lot of information on more advanced topics that were not covered in my previous Mongoose course. I hope you'll join me as we move forward and learn more about Mongoose version 4 here on Pluralsight.

Course Introduction
Welcome to Moving Forward with Mongoose. js. My name is Mark Scott. If you are a Node. js web applications developer who uses MongoDB for your data store, there is a really good chance that you have already had some exposure to Mongoose. js. Perhaps you've already watched my previous course, Introduction to Mongoose for Node. js and MongoDB, and have been working with Mongoose version 3, but now want to move forward with Mongoose version 4. That's primarily what this course is about, taking what you've already learned about the previous version of Mongoose and migrating up to version 4, learning about some breaking changes and some more advanced topics along the way. Let's get started.

Review of Breaking Changes
Welcome to this module on breaking changes. As software developers, especially in the open source space, we're all used to libraries we love and use updating on us and breaking our code. It's not fun, but progress must be made, right? Fortunately, there are not a burdensome amount of breaking changes when moving from Mongoose 3 to 4. Nevertheless, there are breaks, and those need to be addressed. That is what this module is about. Let's get started by taking a look at a comprehensive list of breaking changes and where you can review that information.

New Features
Welcome to this module on new features and improvements. The core contributors to Mongoose 4 have been hard at work providing new features and improvements to existing ones. We won't have time to look at each and every one of those, but we will show you where you can find a comprehensive list of all improvements and new features, and how to drill down into those to see further details should you have the need to do so. We will be looking at new or improved Mongoose features in the following three categories, schemas, validators, and middleware. Some of these features will be introduced in this module, but discussed in greater detail in following modules. Let's get started.

Extending Functionality with Plugins
Welcome to this module on extending existing functionality with Mongoose plug-ins. A schema in Mongoose can have extra functionality plugged into it from a previously defined library. There are a wide variety of reasons why you may want to or need to do this. We'll begin this module by looking at how to build your custom plug-in and then apply that to a schema. We will also explore how your custom plug-in library can be applied to all schemas within your project globally. And finally, we will look at the Mongoose plug-in library, the npm repository where other developers have published and shared plug-ins they have developed for use by the community. Let's get started.

Discriminators
As you've seen by now, our demo project is a storage unit and inventory system where we log items we are storing in our rental unit, saving information like the name of the item stored, a description, an estimated price, and so forth. As you will soon see, using Mongoose discriminators differs from what we saw in the previous modules where we used plug-ins to add datetime audit properties to our item schema. And discriminators are also different than what we did with our itemSaveHelper middleware when we added the required insurance Boolean property to our schema if it was needed, and if it was missing. But then when it came time to update, we then saw how in our itemUpdateHelper middleware we had to get a little creative, and ask if the req. body object had the requiresInsurance property or if it was missing, and then either use the normal item model or the new insuredItem model, which was derived from the item schema to which we added on the Boolean property type we named requiresInsurance. While we were able to in kind of a sneaky way store documents that varied in schema structure in the same MongoDB collection, we had to get a little creative with it, and we had to set the strict option in our schema to false to even allow this at all. In this module, we will look at how to extend our base schema using Mongoose discriminators, so that we can have truly overlapping schema definitions on top of a single MongoDB collection, giving us the ability to store different details for different item documents within the same collection. Before we dig into discriminators, let's first review what inheritance is.

Promises
Welcome to this module on Promises. In this section, we will be looking at promises from a consumer's point of view, that is to say, how we can utilize promises in Mongoose rather than how to build promises. We will also take a look at how to change some of our callback in our demo application to use promises instead. Let's get started.

Course Summary
Well, congratulations on completing this course on Moving Forward with Mongoose 4. Let's do a quick review of what was covered. While it's never any fun having to deal with breaking changes in your libraries that you use and rely upon, we had a few to deal with when moving from Mongoose 3 to 4, and we started the course out by looking into a few of those. As noted in module three, the core contributors to Mongoose 4 have been hard at work providing new features and improvements to existing ones. We explored a few of the more noteworthy changes. In the module on Extending Functionality with Plugins, we discussed and demonstrated how to extend schema functionality, and in our demo project for this module, we developed a custom plug-in to add some additional information to our item description, if that item's value was greater than a determined amount. We then looked at three types of middleware supported by Mongoose 4. 5, document middleware, query middleware, and error handling middleware. To demonstrate middleware and hooks, we built some middleware to help us with saving new and updating existing documents. We learned how Mongoose uses discriminators as a form of schema inheritance, and in our demo project we extended our base item schema to store special item documents within the same MongoDB collection. We closed out this course by briefly exploring what exactly promises are, and then looked at how to use both the default Mongoose promise library mpromise, as well as Bluebird and Q. We altered our demo application to use promises versus a callback function, which gave us cleaner, more discoverable code to deal with. Mongoose 4 has received frequent fixes and improvements during the development of this course. As noted earlier, the core contributors have been hard at work providing improvements. So be sure to keep up on the Mongoose change history found on GitHub. My name is Mark Scott, and I want to personally thank you for watching, and trust that you found the information presented in this course useful to you.