Connecting to MongoDB through Mongoose
Mongoose is a popular object document mapper (ODM) for Node.js that provides a natural interface for working with MongoDB documents, collections, and databases. You can think of Mongoose as a superset of MongoDB functionality that is tailored to work inside Node.js. We will use Mongoose for all the details of connecting to MongoDB, defining our model schemas, and retrieving documents. One of the strengths Mongoose shares with Express is its very lightweight, flexible, and compossible approach to database queries.
Getting ready
To use Mongoose, we will need to install it to our Express application's package.json
file:
npm install mongoose --save
Once saved to our package.json
file, we can import Mongoose into our Express application in order to communicate with our running MongoDB process.
Note
For supplemental information on using Mongoose, you check out the official Mongoose documentation website while working through this section:http://mongoosejs.com/