From the course: Learning Node.js
Unlock the full course today
Join today to access over 24,200 courses taught by industry experts.
Mongoose - Node.js Tutorial
From the course: Learning Node.js
Mongoose
- [Instructor] Mongoose allows us to elegantly work with our mongodb database with object schemas. Object schemas are JavaScript objects we create that will represent the type of data we will be putting in our database. Even though mongodb is NoSQL, and does not have structure, with Mongoose, there is a bit of structure we must design initially. This gives us some benefits of easily interacting with our data through objects, and other things such as validation. Let's begin by installing Mongoose with npm. (typing on keyboard) Then inside our server js, let's require it in. (typing on keyboard) Next let's connect to our mLab database. We will first need the connection string. So let's go back to our mLab database website and copy that from the top. So let's copy this URI. Then above our messages array, let's create a db URL variable, and set it to what we copied. Then let's put in our user credentials. Since I set my username and password to both user, I'll use that. An important note…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.