How it works...

Mongoose is a node module similar to the many other node modules we have used within Express in this book. Its main role is to handle the connection to the MongoDB database. This connection is asynchronously resolved through the URI mongodb://localhost/mean-db. This same request can be modified to connect to different servers or databases. In our case, we are simply connecting to our localhost MongoDB process, and loading the mean-db database:

mongodb://<server>/<data-base>

The connection object we get back from Mongo can bound to event listeners for startup and failure callbacks from Mongoose. Attempting to make requests before MongoDB is connected will simply queue them in Mongoose until a connection is established. Exiting our Express application effectively terminates our connection to MongoDB, and will restart the connection every time we restart Express. This is very handy if using a process manager, such as Forever, to automatically restart our Express application.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.164.120